On Jan 10, 4:20 am, [email protected] wrote: > Author: masak > Date: Sat Jan 10 04:20:05 2009 > New Revision: 35338 > > Modified: > trunk/languages/perl6/src/builtins/any-str.pir > > Log: > [rakudo] added :d and :f filetest operators > > Modified: trunk/languages/perl6/src/builtins/any-str.pir > ============================================================================== > --- trunk/languages/perl6/src/builtins/any-str.pir (original) > +++ trunk/languages/perl6/src/builtins/any-str.pir Sat Jan 10 04:20:05 > 2009 > @@ -21,7 +21,7 @@ > .namespace [] > .sub 'onload' :anon :init :load > $P0 = get_hll_namespace ['Any'] > - > '!EXPORT'('capitalize,chop,chomp,chars,:e,index,lc,lcfirst,rindex,ord,substr,uc,ucfirst,unpack', > 'from'=>$P0) > + > '!EXPORT'('capitalize,chop,chomp,chars,:d,:e,:f,index,lc,lcfirst,rindex,ord,substr,uc,ucfirst,unpack', > 'from'=>$P0) > .end > > @@ -170,6 +170,31 @@ > .return(retv) > .end > > +=item ':d'() > + > + our Bool multi Str::':d' ( Str $filename ) > + > +Returns whether the file with the name indicated by the invocant is a > +directory. > + > +=cut > + > +.sub ':d' :method :multi(_) > + .param int arg :optional > + .param int has_arg :opt_flag > + > + .local string filename > + filename = self > + > + $I0 = stat filename, 2
please .include the proper pasm file defining the various stat fields, and take out the magic number here. > + if $I0 goto file_is_a_dir > + $P0 = get_hll_global ['Bool'], 'False' > + .return ($P0) > + file_is_a_dir: > + $P0 = get_hll_global ['Bool'], 'True' > + .return ($P0) > +.end > + > =item ':e'() > > our Bool multi Str::':e' ( Str $filename ) > @@ -194,6 +219,31 @@ > .return ($P0) > .end > > +=item ':f'() > + > + our Bool multi Str::':f' ( Str $filename ) > + > +Returns whether the file with the name indicated by the invocant is a plain > +file. > + > +=cut > + > +.sub ':f' :method :multi(_) > + .param int arg :optional > + .param int has_arg :opt_flag > + > + .local string filename > + filename = self > + > + $I0 = stat filename, 2 ditto. > + if $I0 goto file_isnt_plain > + $P0 = get_hll_global ['Bool'], 'True' > + .return ($P0) > + file_isnt_plain: > + $P0 = get_hll_global ['Bool'], 'False' > + .return ($P0) > +.end > + > =item fmt > > our Str multi Any::fmt ( Str $format ) ~jerry
