Changeset 30946
- Timestamp:
- 03/08/09 16:55:05 (4 years ago)
- Location:
- lang/perl/Path-Extended/trunk
- Files:
-
- 11 added
- 10 modified
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (3 diffs)
-
Makefile.PL (modified) (2 diffs)
-
lib/Path/Extended.pm (modified) (1 diff)
-
lib/Path/Extended/Class.pm (modified) (2 diffs)
-
lib/Path/Extended/Class/Dir.pm (modified) (4 diffs)
-
lib/Path/Extended/Dir.pm (modified) (6 diffs)
-
lib/Path/Extended/Entity.pm (modified) (3 diffs)
-
t/50_subclass.t (added)
-
t/lib/Path/Extended/Test.pm (added)
-
t/lib/Path/Extended/Test/Compatibility/Basic.pm (modified) (5 diffs)
-
t/lib/Path/Extended/Test/Compatibility/Filesystem.pm (modified) (1 diff)
-
t/lib/Path/Extended/Test/Dir.pm (added)
-
t/lib/Path/Extended/Test/Dir/Next.pm (added)
-
t/lib/Path/Extended/Test/File.pm (added)
-
t/lib/Path/Extended/Test/File/Grep.pm (added)
-
t/lib/Path/Extended/Test/File/Overload.pm (added)
-
t/lib/Path/Extended/Test/Subclass (added)
-
t/lib/Path/Extended/Test/Subclass/Dir.pm (added)
-
t/lib/Path/Extended/Test/Subclass/File.pm (added)
-
t/lib/Path/Extended/Test/Subclass/Import.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Path-Extended/trunk/Changes
r30885 r30946 1 1 Revision history for Path-Extended 2 3 0.10 2009/03/08 4 - fixed a compatibility test which may break under some environment 5 - better pod coverage 6 - reorganized a bit and added "basename" to dir (cf. RT #17312) 7 - better subclassing 8 - forgot to close a directory after ->children, and before ->rmdir 2 9 3 10 0.09 2009/03/06 -
lang/perl/Path-Extended/trunk/MANIFEST
r30767 r30946 15 15 t/30_directory.t 16 16 t/40_compatibility.t 17 t/50_subclass.t 17 18 t/99_pod.t 18 19 t/99_podcoverage.t 20 t/lib/Path/Extended/Test.pm 19 21 t/lib/Path/Extended/Test/Compatibility/Basic.pm 20 22 t/lib/Path/Extended/Test/Compatibility/Filesystem.pm 23 t/lib/Path/Extended/Test/Dir.pm 21 24 t/lib/Path/Extended/Test/Dir/Copy.pm 22 25 t/lib/Path/Extended/Test/Dir/Exists.pm … … 27 30 t/lib/Path/Extended/Test/Dir/Seek.pm 28 31 t/lib/Path/Extended/Test/Entity/Log.pm 32 t/lib/Path/Extended/Test/File.pm 29 33 t/lib/Path/Extended/Test/File/Copy.pm 30 34 t/lib/Path/Extended/Test/File/Grep.pm … … 34 38 t/lib/Path/Extended/Test/File/Slurp.pm 35 39 t/lib/Path/Extended/Test/File/Stat.pm 40 t/lib/Path/Extended/Test/Subclass/Dir.pm 41 t/lib/Path/Extended/Test/Subclass/File.pm 42 t/lib/Path/Extended/Test/Subclass/Import.pm -
lang/perl/Path-Extended/trunk/Makefile.PL
r30767 r30946 12 12 'Carp' => 0, 13 13 'Encode' => 0, 14 'Exporter::Lite' => 0,15 14 'Fcntl' => 0, 16 15 'File::Basename' => 0, … … 23 22 'Log::Dump' => 0, 24 23 'Scalar::Util' => 0, 24 'Sub::Install' => 0, 25 25 'Test::Classy' => '0.04', 26 26 'Test::More' => '0.47', -
lang/perl/Path-Extended/trunk/lib/Path/Extended.pm
r30885 r30946 3 3 use strict; 4 4 use warnings; 5 use base qw( Exporter::Lite ); 6 use Path::Extended::File; 7 use Path::Extended::Dir; 5 use Sub::Install; 8 6 9 our $VERSION = '0. 09';7 our $VERSION = '0.10'; 10 8 11 our @EXPORT = our @EXPORT_OK = qw( file dir ); 9 sub import { 10 my ($class, @imports) = @_; 12 11 13 sub file { Path::Extended::File->new( @_ ) } 14 sub dir { Path::Extended::Dir->new( @_ ) } 12 my $caller = caller; 13 14 @imports = qw( file dir ) unless @imports; 15 foreach my $import (@imports) { 16 next unless $import =~ /^(?:file|dir)$/; 17 my $target = $class.'::'.ucfirst($import); 18 eval "require $target" or die $@; 19 Sub::Install::install_sub({ 20 as => $import, 21 into => $caller, 22 code => sub { $target->new(@_) }, 23 }); 24 Sub::Install::reinstall_sub({ 25 as => $import, 26 into => $class, 27 code => sub { $target->new(@_) }, 28 }); 29 } 30 } 15 31 16 32 1; -
lang/perl/Path-Extended/trunk/lib/Path/Extended/Class.pm
r30767 r30946 3 3 use strict; 4 4 use warnings; 5 use base qw( Exporter::Lite ); 6 use Path::Extended::Class::File; 7 use Path::Extended::Class::Dir; 8 9 our @EXPORT = our @EXPORT_OK = qw( file dir ); 10 11 sub file { Path::Extended::Class::File->new( @_ ) } 12 sub dir { Path::Extended::Class::Dir->new( @_ ) } 5 use base qw( Path::Extended ); 13 6 14 7 1; … … 28 21 =head1 DESCRIPTION 29 22 30 If you want some functionality of L<Path::Extended> but also want more L<Path::Class>-compatible API, try L<Path::Extended::Class>, which is built upon L<Path::Extended> and passes many of the L<Path::Class> tests. What you may miss are foreign expressions, C<recurse> method for a directory,and C<absolute>/C<relative> chains (those of L<Path::Extended::Class> return a string instead of an object).23 If you want some functionality of L<Path::Extended> but also want more L<Path::Class>-compatible API, try L<Path::Extended::Class>, which is built upon L<Path::Extended> and passes many of the L<Path::Class> tests. What you may miss are foreign expressions, and C<absolute>/C<relative> chains (those of L<Path::Extended::Class> return a string instead of an object). 31 24 32 25 =head1 FUNCTIONS -
lang/perl/Path-Extended/trunk/lib/Path/Extended/Class/Dir.pm
r30855 r30946 26 26 sub as_foreign { shift } # does nothing 27 27 28 sub file { shift->_related( file => @_ ); }29 sub subdir { shift->_related( dir => @_ ); }30 31 28 sub dir_list { 32 29 my $self = shift; … … 45 42 } 46 43 47 sub _parts {48 my ($self, $abs) = @_;49 50 my $path = $abs ? $self->absolute : $self->_path;51 my ($vol, $dir, $file) = File::Spec->splitpath( $path );52 return split '/', "$dir$file";53 }54 55 44 sub volume { 56 45 my $self = shift; … … 64 53 65 54 Carp::croak "No second entity given to subsumes()" unless $other; 66 $other = __PACKAGE__->new($other) unless UNIVERSAL::isa($other, __PACKAGE__); 55 my $class = $self->_class('dir'); 56 $other = $class->new($other) unless UNIVERSAL::isa($other, $class); 67 57 $other = $other->dir unless $other->is_dir; 68 58 … … 102 92 103 93 =head1 COMPATIBLE METHODS 104 105 =head2 file, subdir106 107 returns a child L<Path::Extended::Class::File>/L<Path::Extended::Class::Dir> object in the directory. See L<Path::Class::Dir> for details.108 94 109 95 =head2 volume -
lang/perl/Path-Extended/trunk/lib/Path/Extended/Dir.pm
r30855 r30946 27 27 } 28 28 29 sub _parts { 30 my ($self, $abs) = @_; 31 32 my $path = $abs ? $self->absolute : $self->_path; 33 my ($vol, $dir, $file) = File::Spec->splitpath( $path ); 34 return split '/', "$dir$file"; 35 } 36 37 sub basename { 38 my $self = shift; 39 40 return ($self->_parts)[-1]; 41 } 42 29 43 sub open { 30 44 my $self = shift; … … 118 132 sub rmdir { 119 133 my $self = shift; 134 135 $self->close if $self->is_open; 120 136 121 137 if ( $self->exists ) { … … 158 174 } 159 175 } 176 177 sub file { shift->_related( file => @_ ); } 178 sub subdir { shift->_related( dir => @_ ); } 160 179 161 180 sub children { … … 171 190 push @children, $self->_related( $type => $entry ); 172 191 } 192 $self->close; 173 193 return @children; 174 194 } … … 243 263 takes a path or parts of a path of a directory (or a file in the case of C<new_from_file>), and creates a L<Path::Extended::Dir> object. If the path specified is a relative one, it will be converted to the absolute one internally. 244 264 265 =head2 basename 266 267 returns the last part of the directory. 268 245 269 =head2 open, close, read, seek, tell, rewind 246 270 … … 275 299 } 276 300 277 returns a L<Path::Extended::Dir> or L<Path::Extended::File> object to iterate through directory contents (or C<undef> when there's no more items in the directory). The directory will be open with the first C<next>, and close with the last C<next>.301 returns a L<Path::Extended::Dir> or L<Path::Extended::File> object while iterating through the directory (or C<undef> when there's no more items there). The directory will be open with the first C<next>, and close with the last C<next>. 278 302 279 303 =head2 children 280 304 281 305 returns a list of L<Path::Extended::Class::File> and/or L<Path::Extended::Class::Dir> objects listed in the directory. See L<Path::Class::Dir> for details. 306 307 =head2 file, subdir 308 309 returns a child L<Path::Extended::Class::File>/L<Path::Extended::Class::Dir> object in the directory. 310 311 =head2 recurse 312 313 dir('path/to/somewhere')->recurse( callback => sub { 314 my $file_or_dir = shift; 315 ... 316 }); 317 318 takes a hash and iterates through the directory and all its subdirectories recursively, and call the callback function for each entry. Options are: 319 320 =over 4 321 322 =item callback 323 324 a code reference to call for each entry. 325 326 =item depthfirst, preorder 327 328 flags to change the order of processing. 329 330 =back 282 331 283 332 =head1 AUTHOR -
lang/perl/Path-Extended/trunk/lib/Path/Extended/Entity.pm
r30866 r30946 24 24 sub _initialize {} 25 25 26 sub _class { 27 my ($self, $type) = @_; 28 my $class = ref $self; 29 $class =~ s/::(?:File|Dir|Entity)$//; 30 return $class unless $type; 31 return $class.'::'.($type eq 'file' ? 'File' : 'Dir'); 32 } 33 26 34 sub _related { 27 35 my ($self, $type, @parts) = @_; 28 36 29 my $class = 'Path::Extended::'; 30 $class .= 'Class::' if $self->{_compat}; 31 $class .= $type eq 'file' ? 'File' : 'Dir'; 37 my $class = $self->_class($type); 32 38 eval "require $class" or Carp::croak $@; 33 39 my $item; … … 48 54 } 49 55 56 sub _unixify { 57 my ($self, $path) = @_; 58 59 $path =~ s{\\}{/}g if $^O eq 'MSWin32'; 60 61 return $path; 62 } 63 50 64 sub _handle { shift->{handle} } 51 65 … … 166 180 } 167 181 168 sub _unixify {169 my ($self, $path) = @_;170 171 $path =~ s{\\}{/}g if $^O eq 'MSWin32';172 173 return $path;174 }175 176 182 sub stat { 177 183 my $self = shift; -
lang/perl/Path-Extended/trunk/t/lib/Path/Extended/Test/Compatibility/Basic.pm
r30767 r30946 30 30 } 31 31 32 sub test02_dir1 : Tests( 6) {32 sub test02_dir1 : Tests(7) { 33 33 my $class = shift; 34 34 … … 36 36 ok $dir eq 'tmp', $class->message("test 10"); 37 37 ok !$dir->is_absolute, $class->message("test 11"); 38 ok $dir->basename eq 'tmp', $class->message("RT 17312"); 38 39 39 40 my $cat = file($dir, 'foo'); … … 45 46 } 46 47 47 sub test03_dir2 : Tests( 8) {48 sub test03_dir2 : Tests(9) { 48 49 my $class = shift; 49 50 … … 62 63 ok $cat eq '/tmp/foo', $class->message("test 22"); 63 64 ok $cat->isa('Path::Extended::Class::Dir'), $class->message("test 23"); 65 ok $cat->basename eq 'foo', $class->message("RT 17312"); 64 66 } 65 67 … … 120 122 my $dir = dir('one/two/three/four/five'); 121 123 my @d = $dir->dir_list(); 122 ok "@d" eq "one two three four five", $class->message("test 47" ."@d");124 ok "@d" eq "one two three four five", $class->message("test 47"); 123 125 124 126 @d = $dir->dir_list(2); -
lang/perl/Path-Extended/trunk/t/lib/Path/Extended/Test/Compatibility/Filesystem.pm
r30855 r30946 160 160 161 161 my $d = dir('a'); 162 my @children = $d->children;162 my @children = sort $d->children; # following test breaks sometimes 163 163 164 164 is_deeply \@children, ['a/b', 'a/c'];
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)