Changeset 222
- Timestamp:
- 04/08/07 01:10:00 (2 years ago)
- Files:
-
- trunk/src/core/IO-All/Changes (modified) (1 diff)
- trunk/src/core/IO-All/MANIFEST (modified) (1 diff)
- trunk/src/core/IO-All/README (modified) (4 diffs)
- trunk/src/core/IO-All/lib/IO/All.pm (modified) (6 diffs)
- trunk/src/core/IO-All/lib/IO/All.pod (modified) (4 diffs)
- trunk/src/core/IO-All/lib/IO/All/Base.pm (modified) (2 diffs)
- trunk/src/core/IO-All/lib/IO/All/Dir.pm (modified) (1 diff)
- trunk/src/core/IO-All/lib/IO/All/Filesys.pm (modified) (1 diff)
- trunk/src/core/IO-All/lib/IO/All/Link.pm (modified) (1 diff)
- trunk/src/core/IO-All/t/file_spec.t (modified) (2 diffs)
- trunk/src/core/IO-All/t/import_flags.t (added)
- trunk/src/core/IO-All/t/string_open.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/core/IO-All/Changes
r219 r222 5 5 - make catdir work with current dir in addition to other args. 6 6 - make catfile work with current dir in addition to other args. 7 - Add support for import flags like -strict and -utf8 7 8 --- 8 9 version: 0.36 trunk/src/core/IO-All/MANIFEST
r45 r222 44 44 t/file_subclass.t 45 45 t/fileno.t 46 t/import_flags.t 46 47 t/inline_subclass.t 47 48 t/input.t trunk/src/core/IO-All/README
r45 r222 28 28 io('file.txt') > io('copy.txt'); # Invokes File::Copy 29 29 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. 30 35 31 36 # Print the path name of a file: … … 151 156 152 157 And that is a good thing! 158 159 USAGE 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; 153 179 154 180 METHOD ROLE CALL … … 177 203 "send", "separator", "shutdown", "size", "slurp", "socket", "sort", 178 204 "splitdir", "splitpath", "stat", "stdio", "stderr", "stdin", "stdout", 179 "stri ng", "string_ref", "subject", "sysread", "syswrite", "tail",180 "t ell", "temp", "tie", "tmpdir", "to", "touch", "truncate", "type",181 " user", "uid", "unlink", "unlock", "updir", "uri", "utf8", "utime" and182 " 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". 183 209 184 210 Each method is documented further below. … … 693 719 will be in sorted order by name. True by default. 694 720 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 695 727 * tie 696 728 Indicate that the object should be tied to itself, thus allowing it trunk/src/core/IO-All/lib/IO/All.pm
r219 r222 13 13 our @EXPORT = qw(io); 14 14 15 sub io { IO::All->new(@_) }16 17 15 #=============================================================================== 18 16 # Object creation and setup methods … … 55 53 sub autoload {my $self = shift; $autoload } 56 54 57 sub AUTOLOAD {my $self = shift; 55 sub AUTOLOAD { 56 my $self = shift; 58 57 my $method = $IO::All::AUTOLOAD; 59 58 $method =~ s/.*:://; … … 360 359 field _binary => undef; 361 360 field _binmode => undef; 361 field _strict => undef; 362 362 field _utf8 => undef; 363 363 field _handle => undef; … … 366 366 # Public Accessors 367 367 #=============================================================================== 368 field constructor => undef; 368 369 chain block_size => 1024; 369 370 chain errors => undef; … … 388 389 option 'rdonly'; 389 390 option 'rdwr'; 391 option 'strict'; 390 392 391 393 #=============================================================================== … … 416 418 my $self = shift; 417 419 my @args = grep defined, $self->name, @_; 418 io->dir(File::Spec->catdir(@args));420 $self->constructor->()->dir(File::Spec->catdir(@args)); 419 421 } 420 422 sub catfile { 421 423 my $self = shift; 422 424 my @args = grep defined, $self->name, @_; 423 io->file(File::Spec->catfile(@args));425 $self->constructor->()->file(File::Spec->catfile(@args)); 424 426 } 425 427 sub 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, @_) } 428 sub curdir { 429 my $self = shift; 430 $self->constructor->()->dir(File::Spec->curdir); 431 } 432 sub devnull { 433 my $self = shift; 434 $self->constructor->()->file(File::Spec->devnull); 435 } 436 sub rootdir { 437 my $self = shift; 438 $self->constructor->()->dir(File::Spec->rootdir); 439 } 440 sub tmpdir { 441 my $self = shift; 442 $self->constructor->()->dir(File::Spec->tmpdir); 443 } 444 sub updir { 445 my $self = shift; 446 $self->constructor->()->dir(File::Spec->updir); 447 } 448 sub case_tolerant { 449 my $self = shift; 450 File::Spec->case_tolerant; 451 } 452 sub is_absolute { 453 my $self = shift; 454 File::Spec->file_name_is_absolute($self->pathname); 455 } 456 sub path { 457 my $self = shift; 458 map { $self->constructor->()->dir($_) } File::Spec->path; 459 } 460 sub splitpath { 461 my $self = shift; 462 File::Spec->splitpath($self->pathname); 463 } 464 sub splitdir { 465 my $self = shift; 466 File::Spec->splitdir($self->pathname); 467 } 468 sub catpath { 469 my $self = shift; 470 $self->constructor->(File::Spec->catpath(@_)); 471 } 472 sub abs2rel { 473 my $self = shift; 474 File::Spec->abs2rel($self->pathname, @_); 475 } 476 sub rel2abs { 477 my $self = shift; 478 File::Spec->rel2abs($self->pathname, @_); 479 } 439 480 440 481 #=============================================================================== trunk/src/core/IO-All/lib/IO/All.pod
r45 r222 30 30 io('file.txt') > io('copy.txt'); # Invokes File::Copy 31 31 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. 32 37 33 38 # Print the path name of a file: … … 153 158 154 159 And that is a B<good thing>! 160 161 =head1 USAGE 162 163 Normally just say: 164 165 use IO::All; 166 167 and IO::All will export a single function called C<io>, which contructs all IO 168 objects. 169 170 You can also pass global flags like this: 171 172 use IO::All -strict -utf8 -foobar; 173 174 Which automatically makes those method calls on every new IO object. In other 175 words this: 176 177 my $io = io('lalala.txt'); 178 179 becomes this: 180 181 my $io = io('lalala.txt')->strict->utf8->foobar; 155 182 156 183 =head1 METHOD ROLE CALL … … 182 209 C<send>, C<separator>, C<shutdown>, C<size>, C<slurp>, C<socket>, 183 210 C<sort>, C<splitdir>, C<splitpath>, C<stat>, C<stdio>, C<stderr>, 184 C<stdin>, C<stdout>, C<stri ng>, C<string_ref>, C<subject>, C<sysread>,185 C<sys write>, C<tail>, C<tell>, C<temp>, C<tie>, C<tmpdir>, C<to>,186 C<to uch>, C<truncate>, C<type>, C<user>, C<uid>, C<unlink>, C<unlock>,187 C<u pdir>, C<uri>, C<utf8>, C<utime> and C<write>.211 C<stdin>, C<stdout>, C<strict>, C<string>, C<string_ref>, C<subject>, 212 C<sysread>, C<syswrite>, C<tail>, C<tell>, C<temp>, C<tie>, C<tmpdir>, 213 C<to>, C<touch>, C<truncate>, C<type>, C<user>, C<uid>, C<unlink>, 214 C<unlock>, C<updir>, C<uri>, C<utf8>, C<utime> and C<write>. 188 215 189 216 Each method is documented further below. … … 745 772 be in sorted order by name. True by default. 746 773 774 =item * strict 775 776 Check the return codes of every single system call. To turn this on for all 777 calls in your module, use: 778 779 use IO::All -strict; 780 747 781 =item * tie 748 782 trunk/src/core/IO-All/lib/IO/All/Base.pm
r45 r222 6 6 sub import { 7 7 my $class = shift; 8 my $flag = shift|| '';8 my $flag = $_[0] || ''; 9 9 my $package = caller; 10 10 no strict 'refs'; … … 18 18 } 19 19 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 29 sub 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; 22 40 } 23 41 } trunk/src/core/IO-All/lib/IO/All/Dir.pm
r45 r222 145 145 my $name = $self->readdir; 146 146 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)); 148 148 $io->absolute if $self->is_absolute; 149 149 return $io; trunk/src/core/IO-All/lib/IO/All/Filesys.pm
r45 r222 59 59 ? UNIVERSAL::isa($new, 'IO::All') 60 60 ? $new 61 : $self-> new($new)61 : $self->constructor->($new) 62 62 : undef; 63 63 } trunk/src/core/IO-All/lib/IO/All/Link.pm
r45 r222 15 15 sub readlink { 16 16 my $self = shift; 17 IO::All->new(CORE::readlink($self->name));17 $self->constructor->(CORE::readlink($self->name)); 18 18 } 19 19 trunk/src/core/IO-All/t/file_spec.t
r219 r222 2 2 use strict; 3 3 use warnings; 4 use Test::More tests => 2 8;4 use Test::More tests => 27; 5 5 use IO::All; 6 6 use IO_All_Test; … … 13 13 is(ref(io->devnull), 'IO::All::File'); 14 14 ok(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')); 16 17 ok(io->rootdir->is_dir); 17 18 ok(io->tmpdir->is_dir); trunk/src/core/IO-All/t/string_open.t
r45 r222 1 use IO::All;2 1 use lib 't', 'lib'; 3 2 use strict;
