parser

Simple visitors counter

Misha v.3 [December 19, 2002]

@counter[i_file_name][file_name;file;count]
^if(!def $i_file_name){^throw[counter;file_name not specified]}
$file_name[${i_file_name}.count]
^file:lock[${file_name}.lock]{
	^try{
		$file[^file::load[text;$file_name]]
		$result($file.text)
	}{
		$exception.handled(1)
		$result(0)
	}
	$count[^eval($result+1)]
	^count.save[$file_name]
}
#end @counter[]

How to call:

@main[]
^counter[/news/index]

This operator works the same way as operator counter provided by Parser v.2: "The Operator returns the value of counter stored in file and then increases its value by 1. If specified file doesn't exist, it will be created and the value in it will be set to 0."

If Parser doesn't have enough rights to save the file, there will be a fatal error. If you don't want the operator to behave like this, edit the code.