Badger
view release on metacpan or search on metacpan
Version 0.09 - 8th February 2012
Added Badger::Codec::Timestamp. Changed Badger::Timestamp to numify
values to remove leading zeroes (e.g. 2012/04/20 now yields a month of 4
instead of 04).
Fixed some obscure bugs in the module loading code in Badger::Class and
related modules that could potentially cause unpredictable results on
case insensitive file systems (e.g. Apple's HFS with default settings).
Added the restat() method to Badger::Filesystem::Path.
Added documentation for various methods that was missing. Temporary
disabled the Pod::Coverage tests on AUTOMATED_TESTING systems. We know
there's still stuff to do.
Added SLASH to Badger::Constants
Version 0.08 - 13th January 2012
Restored the $VERSION variable to Badger.pm rather than using the
"version" import hook in Badger::Class which confused PAUSE.
lib/Badger/Filesystem.pm view on Meta::CPAN
sub directory_exists {
my $self = shift;
my $stats = $self->stat_path(shift) || return;
return -d _ ? $stats : 0; # relies on cached stat
}
sub stat_path {
my $self = shift;
my $path = $self->definitive_read(shift) || return;
my @stats = (stat($path), -r _, -w _, -x _, -o _, $path);
return $self->error_msg( bad_stat => $self->{ path } )
unless @stats;
return wantarray
? @stats
: \@stats;
}
sub chmod_path {
lib/Badger/Filesystem.pm view on Meta::CPAN
=head2 file_exists($path)
Returns true if the path exists and is a file, false if not.
=head2 dir_exists($path) / directory_exists($path)
Returns true if the path exists and is a directory, false if not.
=head2 stat_path($path)
Performs a C<stat()> on the filesystem path. It returns a list (in list
context) or a reference to a list (in scalar context) containing 17 items.
The first 13 are those returned by Perl's inbuilt C<stat()> function. The
next 3 items are flags indicating if the file is readable, writeable and/or
executable. The final item is a flag indicating if the file is owned by the
current user (i.e. owner of the current process.
A summary of the fields is shown below. See C<perldoc -f stat> and the
L<stat()|Badger::Filesystem::Path/stat()> method in
L<Badger::Filesystem::Path> for further details.
Field Description
--------------------------------------------------------
0 device number of filesystem
1 inode number
2 file mode (type and permissions)
3 number of (hard) links to the file
4 numeric user ID of fileâs owner
5 numeric group ID of fileâs owner
lib/Badger/Filesystem/Path.pm view on Meta::CPAN
$path->create; # FAIL
$dir->create; # OK
$file->create; # OK
=head2 chmod($perms)
This method changes the file permissions on a file or directory.
$file->chmod(0775);
=head2 stat()
Performs a filesystem C<stat> on the path and returns a list (in list
context), or a reference to a list (in scalar context) containing the 13
information elements.
@list = $path->stat; # list context
$list = $path->stat; # scalar context
A summary of the fields is shown below. See C<perldoc -f stat> for complete
details. Each of the individual fields can also be accessed via their own
lib/Badger/Filesystem/Path.pm view on Meta::CPAN
In addition to those that are returned by Perl's inbuilt C<stat> function,
this method returns four additional flags.
13 readable() file is readable by current process
14 writeable() file is writeable by current process
15 executable() file is executable by current process
16 owner() file is owned by current process
=head2 stats()
A wrapper around the L<stat()> method which caches the results to avoid
making repeated filesystem calls.
@list = $path->stats; # list context
$list = $path->stats; # scalar context
Note that the L<accessed()>, L<created()> and L<modified()> methods also
cache the L<Badger::Timestamp> objects they create to represent the
access, creation and modification times respectively.
=head2 restat()
Clears any cached values stored by the L<stats()>, L<accessed()>,
L<created()> and L<modified()> methods and calls L<stats()> to reload
(and re-cache) the data from a L<stat()> call.
=head2 device()
Returns the device number for the file. See L<stat()>.
=head2 inode()
Returns the inode number for the file. See L<stat()>.
=head2 mode()
Returns the file mode for the file. Note that this contains both the
file type and permissions. See L<stat()>.
=head2 permissions() / perms()
Returns the file permissions. This is equivalent to
C<< $file->mode & 0777 >>.
=head2 links()
Returns the number of hard links to the file. See L<stat()>.
=head2 user()
Returns the numeric user ID of the file's owner. See L<stat()>.
=head2 group()
Returns the numeric group ID of the file's group. See L<stat()>.
=head2 device_type()
Returns the device identifier (for special files only). See L<stat()>.
=head2 size()
Returns the total size of the file in bytes. See L<stat()>.
=head2 atime()
Returns the time (in seconds since the epoch) that the file was last accessed.
See L<stat()>.
=head2 accessed()
Returns a L<Badger::Timestamp> object for the L<atime()> value. This object
will auto-stringify to produce an ISO-8601 formatted date. You can also
call various methods to access different parts of the time and/or date.
print $file->accessed; # 2009/04/20 16:25:00
print $file->accessed->date; # 2009/04/20
print $file->accessed->year; # 2009
=head2 mtime()
Returns the time (in seconds since the epoch) that the file was last modified.
See L<stat()>.
=head2 modified()
Returns a L<Badger::Timestamp> object for the L<mtime()> value.
print $file->modified; # 2009/04/20 16:25:00
print $file->modified->time; # 16:25:0
print $file->modified->hour; # 16
=head2 ctime()
Returns the time (in seconds since the epoch) that the file was created. See
L<stat()>.
=head2 created()
Returns a L<Badger::Timestamp> object for the L<ctime()> value.
print $file->created; # 2009/04/20 16:25:00
print $file->created->date; # 2009/04/20
print $file->created->time; # 16:25:00
=head2 block_size()
Returns the preferred block size for file system I/O on the file. See
L<stat()>.
=head2 blocks()
Returns the actual number of blocks allocated to the file. See L<stat()>.
=head2 readable()
Returns a true value if the file is readable by the current user (i.e. the
owner of the current process), false if not. See L<stat()>.
=head2 writeable()
Returns a true value if the file is writeable by the current user (i.e. the
owner of the current process), false if not. See L<stat()>.
=head2 executable()
Returns a true value if the file is executable by the current user (i.e. the
owner of the current process), false if not. See L<stat()>.
=head2 owner()
Returns a true value if the file is owned by the current user (i.e. the
owner of the current process), false if not. See L<stat()>.
=head2 filesystem()
Returns a reference to a L<Badger::Filesystem> object, or the name of the
filesystem class (e.g. L<Badger::Filesystem> or a subclass) that created
the path object. If this is undefined then the default value defined in
the L<$FILESYSTEM> class variable is returned. Unless you've changed it,
or re-defined it in a subclass, this value will be C<Badger::Filesystem>.
The end result is that you can use the C<filesystem> method to access a
pod/Badger/Changes.pod view on Meta::CPAN
=head2 Version 0.09 - 8th February 2012
Added L<Badger::Codec::Timestamp>. Changed L<Badger::Timestamp> to numify
values to remove leading zeroes (e.g. 2012/04/20 now yields a month of 4
instead of 04).
Fixed some obscure bugs in the module loading code in L<Badger::Class> and
related modules that could potentially cause unpredictable results on
case insensitive file systems (e.g. Apple's HFS with default settings).
Added the L<restat()|Badger::Filesystem::Path/restat()> method to
L<Badger::Filesystem::Path>.
Added documentation for various methods that was missing. Temporary
disabled the Pod::Coverage tests on AUTOMATED_TESTING systems. We know
there's still stuff to do.
Added SLASH to Badger::Constants
=head2 Version 0.08 - 13th January 2012
t/filesystem/file.t view on Meta::CPAN
my $file = $FILE->new('file.t');
ok( $file, 'created a new file' );
is( $file->name, 'file.t', 'got file name' );
ok( ! $file->volume, 'got (no) file volume' );
ok( ! $file->dir, 'got (no) file directory' );
ok( ! $file->is_absolute, 'file is not absolute' );
$file = $FILE->new([@tdir, 'file.t']);
ok( $file->exists, 'file exists' );
my @stat = (stat($file->path), -r _, -w _, -x _, -o _);
foreach my $m (@STAT_FIELDS) {
is( $file->$m, $stat[0], "file $m is " . shift(@stat) );
}
my $expect = $FS->dir($cwd, @tdir, 'file.t');
is( $file->absolute, $expect, "absolute path is $expect" );
ok( $FILE->new(path => '/example/file.foo')->is_absolute, 'file is absolute' );
ok( $FILE->new(name => 'file.foo', directory => '/example')->is_absolute, 'directory file is absolute' );
ok( $FILE->new(name => 'file.foo', dir => '/example')->is_absolute, 'dir file is absolute' );
( run in 1.218 second using v1.01-cache-2.11-cpan-49f99fa48dc )