Changeset 21574 for perl5

Show
Ignore:
Timestamp:
07/27/08 18:44:51 (4 months ago)
Author:
fglock
Message:

[v6.pm] improved perl(), slurp()

Location:
perl5/Pugs-Compiler-Perl6/lib/Pugs
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • perl5/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm

    r21573 r21574  
    802802                || $subname eq 'index' || $subname eq 'undef' || $subname eq 'rand' || $subname eq 'int'  
    803803                || $subname eq 'splice' || $subname eq 'keys' || $subname eq 'values' || $subname eq 'sort'  
    804                 || $subname eq 'chomp' || $subname eq 'lc' || $subname eq 'abs'  
     804                || $subname eq 'chomp' || $subname eq 'lc' || $subname eq 'abs' || $subname eq 'sleep'  
    805805                )  
    806806            { 
     
    840840            if ($subname eq 'open') { 
    841841                return 'Perl6::Internals::open('. _emit_parameter_capture( $n->{param} ) . ')'; 
     842            } 
     843            if ($subname eq 'slurp') { 
     844                return 'Pugs::Runtime::Perl6::IO::slurp'. emit_parenthesis( $n->{param} ); 
    842845            } 
    843846 
  • perl5/Pugs-Compiler-Perl6/lib/Pugs/Runtime/Perl6.pm

    r21566 r21574  
    2323sub perl { 
    2424    local $Data::Dumper::Terse    = 1; 
    25     my $can = UNIVERSAL::can($_[0] => 'perl'); 
    26     if ($can) { 
    27         $can->($_[0]); 
    28     } 
    29     else { 
    30         Dumper($_[0]); 
    31     } 
     25    my $self = shift; 
     26    my $can = UNIVERSAL::can($self => 'perl'); 
     27    my $v = $can 
     28        ? $can->($self) 
     29        : Dumper($self); 
     30    chomp $v; 
     31    return $v . ', ' . perl( @_ ) if @_; 
     32    return $v; 
    3233} 
    3334 
     
    184185     
    185186    sub slurp { 
    186         my $self = $_[0]; 
    187         my $content; 
    188         local $/;  
    189         $content = <$self>; 
    190         return bless \$content, 'Pugs::Runtime::Perl6::Scalar'; 
     187        if ( wantarray ) { 
     188            my @a; 
     189            if ( ref( $_[0] ) eq 'IO::File' ) { 
     190                my $f = shift; 
     191                @a = <$f>; 
     192            } 
     193            else { 
     194                local( @ARGV ) = ( @_ );  
     195                @a = <ARGV>; 
     196            } 
     197            chomp @a; 
     198            return @a; 
     199        } 
     200 
     201            if ( ref( $_[0] ) eq 'IO::File' ) { 
     202                return <$_[0]>; 
     203            } 
     204            else { 
     205                local( $/, @ARGV ) = ( undef, @_ );  
     206                return <ARGV>; 
     207            } 
    191208    } 
    192209 
  • perl5/Pugs-Compiler-Perl6/lib/Pugs/Runtime/Perl6Prelude.pm

    r12128 r21574  
    1515sub NaN is export { Pugs::Runtime::Perl6::NaN } 
    1616 
    17 sub slurp { ... } # Slurps in an entire file 
     17# sub slurp { ... } # Slurps in an entire file 
    1818 
    1919module Perl6::Internals; 
     
    2121sub compile_pir($code) { ... } 
    2222sub exit($status)   is export { use v5; CORE::exit($status); use v6; } 
    23 sub sleep($seconds) is export { use v5; CORE::sleep($seconds); use v6; } 
     23# sub sleep($seconds) is export { use v5; CORE::sleep($seconds); use v6; } 
    2424 
    2525sub open($file) { use v5; my $fh = IO::File->new; $fh->open($file); $fh; use v6; }