package psychorigid; use Filter::Simple; use diagnostics; sub ctype { my @ctypes = split /;/,shift; my $code; my $argnum=0; # # Few tests added, we should probably add A LOT more for a real module. # my %CODE = ( 'byte'=>' warn "arg !! ($_[!!]) IS NOT a byte" if $_[!!]!~/^-?\d{1,3}$/ || ($_[!!]>127) || ($_[!!]<-128);', 'short'=>' warn "arg !! ($_[!!]) IS NOT a short" if $_[!!]!~/^-?\d{1,5}$/ || ($_[!!]>32767) || ($_[!!]<-32768);', 'int'=>' warn "arg !! ($_[!!]) IS NOT an int" if $_[!!]!~/^-?\d{1,10}$/ || ($_[!!]>2147483647) || ($_[!!]<-2147483648);', 'char'=>' warn "arg !! ($_[!!]) IS NOT a char" if $_[!!]!~/^\w$/;', ); foreach my $ctype (@ctypes) { my $val=$CODE{$ctype}; $val=~s/!!/$argnum/g; $argnum++; $code.=$val."\n"; } return $code; } sub check { my $func_decl = shift; my $check_code = ctype(shift); return "$func_decl {\n$check_code" } FILTER { s/(sub\s+.+?)\s*{\s*#\s*!([^!]*)!/check($1,$2)/e; # # Uncomment the following line to see the changes applied by the filter # #print "\n$_\n"; }; 1; #### #!/usr/bin/perl # # The following line can be commented and the code # will still be valid. # use psychorigid; # Add additional tests like some psychorigid language ;-) sub toto { # !char;int! print "ok dans toto\n"; } toto('s','12245666666');