develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35338 - trunk/languages/perl6/src/builtins

Thread Next
From:
masak
Date:
January 10, 2009 04:20
Subject:
[svn:parrot] r35338 - trunk/languages/perl6/src/builtins
Message ID:
20090110122005.EFA93CB9F9@x12.develooper.com
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
+    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
+    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 )

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About