Changeset 222

Show
Ignore:
Timestamp:
04/08/07 01:10:00 (2 years ago)
Author:
ingy
Message:
 r3794@dhcp199:  ingy | 2007-04-07 19:59:59 +0900
 0.37 release
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/IO-All/Changes

    r219 r222  
    55- make catdir work with current dir in addition to other args. 
    66- make catfile work with current dir in addition to other args. 
     7- Add support for import flags like -strict and -utf8 
    78--- 
    89version: 0.36 
  • trunk/src/core/IO-All/MANIFEST

    r45 r222  
    4444t/file_subclass.t 
    4545t/fileno.t 
     46t/import_flags.t 
    4647t/inline_subclass.t 
    4748t/input.t 
  • trunk/src/core/IO-All/README

    r45 r222  
    2828        io('file.txt') > io('copy.txt');            # Invokes File::Copy 
    2929        io('more.txt') >> io('all.txt');            # Add on to a file 
     30 
     31        # UTF-8 Support 
     32        $contents = io('file.txt')->utf8->all;      # Turn on utf8 
     33        use IO::All -utf8;                          # Turn on utf8 for all io 
     34        $contents = io('file.txt')->all;            #   by default in this package. 
    3035 
    3136        # Print the path name of a file: 
     
    151156 
    152157    And that is a good thing! 
     158 
     159USAGE 
     160    Normally just say: 
     161 
     162        use IO::All; 
     163 
     164    and IO::All will export a single function called "io", which contructs 
     165    all IO objects. 
     166 
     167    You can also pass global flags like this: 
     168 
     169        use IO::All -strict -utf8 -foobar; 
     170 
     171    Which automatically makes those method calls on every new IO object. In 
     172    other words this: 
     173 
     174        my $io = io('lalala.txt'); 
     175 
     176    becomes this: 
     177 
     178        my $io = io('lalala.txt')->strict->utf8->foobar; 
    153179 
    154180METHOD ROLE CALL 
     
    177203    "send", "separator", "shutdown", "size", "slurp", "socket", "sort", 
    178204    "splitdir", "splitpath", "stat", "stdio", "stderr", "stdin", "stdout", 
    179     "string", "string_ref", "subject", "sysread", "syswrite", "tail", 
    180     "tell", "temp", "tie", "tmpdir", "to", "touch", "truncate", "type", 
    181     "user", "uid", "unlink", "unlock", "updir", "uri", "utf8", "utime" and 
    182     "write". 
     205    "strict", "string", "string_ref", "subject", "sysread", "syswrite", 
     206    "tail", "tell", "temp", "tie", "tmpdir", "to", "touch", "truncate", 
     207    "type", "user", "uid", "unlink", "unlock", "updir", "uri", "utf8", 
     208    "utime" and "write". 
    183209 
    184210    Each method is documented further below. 
     
    693719        will be in sorted order by name. True by default. 
    694720 
     721    * strict 
     722        Check the return codes of every single system call. To turn this on 
     723        for all calls in your module, use: 
     724 
     725            use IO::All -strict; 
     726 
    695727    * tie 
    696728        Indicate that the object should be tied to itself, thus allowing it 
  • trunk/src/core/IO-All/lib/IO/All.pm

    r219 r222  
    1313our @EXPORT = qw(io); 
    1414 
    15 sub io { IO::All->new(@_) } 
    16  
    1715#=============================================================================== 
    1816# Object creation and setup methods 
     
    5553sub autoload {my $self = shift; $autoload } 
    5654 
    57 sub AUTOLOAD {my $self = shift; 
     55sub AUTOLOAD { 
     56    my $self = shift; 
    5857    my $method = $IO::All::AUTOLOAD; 
    5958    $method =~ s/.*:://; 
     
    360359field _binary => undef; 
    361360field _binmode => undef; 
     361field _strict => undef; 
    362362field _utf8 => undef; 
    363363field _handle => undef; 
     
    366366# Public Accessors 
    367367#=============================================================================== 
     368field constructor => undef; 
    368369chain block_size => 1024; 
    369370chain errors => undef; 
     
    388389option 'rdonly'; 
    389390option 'rdwr'; 
     391option 'strict'; 
    390392 
    391393#=============================================================================== 
     
    416418    my $self = shift; 
    417419    my @args = grep defined, $self->name, @_; 
    418     io->dir(File::Spec->catdir(@args)); 
     420    $self->constructor->()->dir(File::Spec->catdir(@args)); 
    419421}  
    420422sub catfile { 
    421423    my $self = shift; 
    422424    my @args = grep defined, $self->name, @_; 
    423     io->file(File::Spec->catfile(@args)); 
     425    $self->constructor->()->file(File::Spec->catfile(@args)); 
    424426}  
    425427sub join {my $self = shift; $self->catfile(@_) }  
    426 sub curdir {my $self = shift; $self->new->dir(File::Spec->curdir) }  
    427 sub devnull {my $self = shift; $self->new->file(File::Spec->devnull) }  
    428 sub rootdir {my $self = shift; $self->new->dir(File::Spec->rootdir) }  
    429 sub tmpdir {my $self = shift; $self->new->dir(File::Spec->tmpdir) }  
    430 sub updir {my $self = shift; $self->new->dir(File::Spec->updir) }  
    431 sub case_tolerant {my $self = shift; File::Spec->case_tolerant }  
    432 sub is_absolute {my $self = shift; File::Spec->file_name_is_absolute($self->pathname) } 
    433 sub path {my $self = shift; map { $self->new->dir($_) } File::Spec->path }  
    434 sub splitpath {my $self = shift; File::Spec->splitpath($self->pathname) }  
    435 sub splitdir {my $self = shift; File::Spec->splitdir($self->pathname) }  
    436 sub catpath {my $self = shift; $self->new(File::Spec->catpath(@_)) }  
    437 sub abs2rel {my $self = shift; File::Spec->abs2rel($self->pathname, @_) }  
    438 sub rel2abs {my $self = shift; File::Spec->rel2abs($self->pathname, @_) } 
     428sub curdir { 
     429    my $self = shift; 
     430    $self->constructor->()->dir(File::Spec->curdir); 
     431}  
     432sub devnull { 
     433    my $self = shift; 
     434    $self->constructor->()->file(File::Spec->devnull); 
     435}  
     436sub rootdir { 
     437    my $self = shift; 
     438    $self->constructor->()->dir(File::Spec->rootdir); 
     439}  
     440sub tmpdir { 
     441    my $self = shift; 
     442    $self->constructor->()->dir(File::Spec->tmpdir); 
     443}  
     444sub updir { 
     445    my $self = shift; 
     446    $self->constructor->()->dir(File::Spec->updir); 
     447}  
     448sub case_tolerant { 
     449    my $self = shift; 
     450    File::Spec->case_tolerant; 
     451}  
     452sub is_absolute { 
     453    my $self = shift; 
     454    File::Spec->file_name_is_absolute($self->pathname); 
     455
     456sub path { 
     457    my $self = shift; 
     458    map { $self->constructor->()->dir($_) } File::Spec->path; 
     459}  
     460sub splitpath { 
     461    my $self = shift; 
     462    File::Spec->splitpath($self->pathname); 
     463}  
     464sub splitdir { 
     465    my $self = shift; 
     466    File::Spec->splitdir($self->pathname); 
     467}  
     468sub catpath { 
     469    my $self = shift; 
     470    $self->constructor->(File::Spec->catpath(@_)); 
     471}  
     472sub abs2rel { 
     473    my $self = shift; 
     474    File::Spec->abs2rel($self->pathname, @_); 
     475}  
     476sub rel2abs { 
     477    my $self = shift; 
     478    File::Spec->rel2abs($self->pathname, @_); 
     479
    439480 
    440481#=============================================================================== 
  • trunk/src/core/IO-All/lib/IO/All.pod

    r45 r222  
    3030    io('file.txt') > io('copy.txt');            # Invokes File::Copy 
    3131    io('more.txt') >> io('all.txt');            # Add on to a file 
     32 
     33    # UTF-8 Support 
     34    $contents = io('file.txt')->utf8->all;      # Turn on utf8 
     35    use IO::All -utf8;                          # Turn on utf8 for all io 
     36    $contents = io('file.txt')->all;            #   by default in this package. 
    3237 
    3338    # Print the path name of a file: 
     
    153158 
    154159And that is a B<good thing>! 
     160 
     161=head1 USAGE 
     162 
     163Normally just say: 
     164 
     165    use IO::All; 
     166 
     167and IO::All will export a single function called C<io>, which contructs all IO 
     168objects. 
     169 
     170You can also pass global flags like this: 
     171 
     172    use IO::All -strict -utf8 -foobar; 
     173 
     174Which automatically makes those method calls on every new IO object. In other 
     175words this: 
     176 
     177    my $io = io('lalala.txt'); 
     178 
     179becomes this: 
     180 
     181    my $io = io('lalala.txt')->strict->utf8->foobar; 
    155182 
    156183=head1 METHOD ROLE CALL 
     
    182209C<send>, C<separator>, C<shutdown>, C<size>, C<slurp>, C<socket>, 
    183210C<sort>, C<splitdir>, C<splitpath>, C<stat>, C<stdio>, C<stderr>, 
    184 C<stdin>, C<stdout>, C<string>, C<string_ref>, C<subject>, C<sysread>, 
    185 C<syswrite>, C<tail>, C<tell>, C<temp>, C<tie>, C<tmpdir>, C<to>, 
    186 C<touch>, C<truncate>, C<type>, C<user>, C<uid>, C<unlink>, C<unlock>, 
    187 C<updir>, C<uri>, C<utf8>, C<utime> and C<write>. 
     211C<stdin>, C<stdout>, C<strict>, C<string>, C<string_ref>, C<subject>, 
     212C<sysread>, C<syswrite>, C<tail>, C<tell>, C<temp>, C<tie>, C<tmpdir>, 
     213C<to>, C<touch>, C<truncate>, C<type>, C<user>, C<uid>, C<unlink>, 
     214C<unlock>, C<updir>, C<uri>, C<utf8>, C<utime> and C<write>. 
    188215 
    189216Each method is documented further below. 
     
    745772be in sorted order by name. True by default. 
    746773 
     774=item * strict 
     775 
     776Check the return codes of every single system call. To turn this on for all 
     777calls in your module, use: 
     778 
     779    use IO::All -strict; 
     780 
    747781=item * tie 
    748782 
  • trunk/src/core/IO-All/lib/IO/All/Base.pm

    r45 r222  
    66sub import { 
    77    my $class = shift; 
    8     my $flag = shift || ''; 
     8    my $flag = $_[0] || ''; 
    99    my $package = caller; 
    1010    no strict 'refs'; 
     
    1818    } 
    1919    else { 
    20         *{$package . "::$_"} = \&{$class . "::$_"} 
    21           for @{$class . '::EXPORT'}; 
     20        my @flags = @_; 
     21        for my $export (@{$class . '::EXPORT'}) { 
     22            *{$package . "::$export"} = $export eq 'io'  
     23            ? $class->generate_constructor(@flags) 
     24            : \&{$class . "::$export"}; 
     25        } 
     26    } 
     27
     28 
     29sub generate_constructor { 
     30    my $class = shift; 
     31    my @flags = grep { s/^-// } @_; 
     32    my $constructor; 
     33    $constructor = sub { 
     34        my $self = $class->new(@_); 
     35        for my $flag (@flags) { 
     36            $self->$flag; 
     37        } 
     38        $self->constructor($constructor); 
     39        return $self; 
    2240    } 
    2341} 
  • trunk/src/core/IO-All/lib/IO/All/Dir.pm

    r45 r222  
    145145    my $name = $self->readdir; 
    146146    return unless defined $name; 
    147     my $io = IO::All->new(File::Spec->catfile($self->pathname, $name)); 
     147    my $io = $self->constructor->(File::Spec->catfile($self->pathname, $name)); 
    148148    $io->absolute if $self->is_absolute; 
    149149    return $io; 
  • trunk/src/core/IO-All/lib/IO/All/Filesys.pm

    r45 r222  
    5959      ? UNIVERSAL::isa($new, 'IO::All') 
    6060        ? $new 
    61         : $self->new($new) 
     61        : $self->constructor->($new) 
    6262      : undef; 
    6363} 
  • trunk/src/core/IO-All/lib/IO/All/Link.pm

    r45 r222  
    1515sub readlink { 
    1616    my $self = shift; 
    17     IO::All->new(CORE::readlink($self->name)); 
     17    $self->constructor->(CORE::readlink($self->name)); 
    1818} 
    1919 
  • trunk/src/core/IO-All/t/file_spec.t

    r219 r222  
    22use strict; 
    33use warnings; 
    4 use Test::More tests => 28
     4use Test::More tests => 27
    55use IO::All; 
    66use IO_All_Test; 
     
    1313is(ref(io->devnull), 'IO::All::File'); 
    1414ok(io->devnull->print('IO::All')); 
    15 ok(IO::All->devnull->print('IO::All')); 
     15# Not supporting class calls anymore. Objects only. 
     16# ok(IO::All->devnull->print('IO::All')); 
    1617ok(io->rootdir->is_dir); 
    1718ok(io->tmpdir->is_dir); 
  • trunk/src/core/IO-All/t/string_open.t

    r45 r222  
    1 use IO::All; 
    21use lib 't', 'lib'; 
    32use strict;