[Moose-commits] r7311 - in File-Stat-Moose/tags/0.05: . trunk
trunk/lib/File/Stat trunk/t/tlib/File/Stat trunk/xt
dexter at code2.0beta.co.uk
dexter at code2.0beta.co.uk
Wed Jan 14 12:20:44 GMT 2009
Author: dexter
Date: 2009-01-14 04:20:43 -0800 (Wed, 14 Jan 2009)
New Revision: 7311
Added:
File-Stat-Moose/tags/0.05/trunk/
File-Stat-Moose/tags/0.05/trunk/Build.PL
File-Stat-Moose/tags/0.05/trunk/eg/
File-Stat-Moose/tags/0.05/trunk/lib/
File-Stat-Moose/tags/0.05/trunk/lib/File/Stat/Moose.pm
File-Stat-Moose/tags/0.05/trunk/t/
File-Stat-Moose/tags/0.05/trunk/t/tlib/File/Stat/MooseTest.pm
File-Stat-Moose/tags/0.05/trunk/xt/
File-Stat-Moose/tags/0.05/trunk/xt/distribution.t
Removed:
File-Stat-Moose/tags/0.05/trunk/Build.PL
File-Stat-Moose/tags/0.05/trunk/eg/
File-Stat-Moose/tags/0.05/trunk/lib/
File-Stat-Moose/tags/0.05/trunk/lib/File/Stat/Moose.pm
File-Stat-Moose/tags/0.05/trunk/t/
File-Stat-Moose/tags/0.05/trunk/t/tlib/File/Stat/MooseTest.pm
File-Stat-Moose/tags/0.05/trunk/xt/
File-Stat-Moose/tags/0.05/trunk/xt/distribution.t
Log:
* svn tag File-Stat-Moose 0.05
Copied: File-Stat-Moose/tags/0.05/trunk (from rev 7306, File-Stat-Moose/trunk)
Deleted: File-Stat-Moose/tags/0.05/trunk/Build.PL
===================================================================
--- File-Stat-Moose/trunk/Build.PL 2009-01-14 11:46:51 UTC (rev 7306)
+++ File-Stat-Moose/tags/0.05/trunk/Build.PL 2009-01-14 12:20:43 UTC (rev 7311)
@@ -1,54 +0,0 @@
-#!/usr/bin/perl
-
-use 5.008;
-
-use strict;
-use warnings;
-
-use Module::Build;
-
-my $module = 'File::Stat::Moose';
-
-(my $dist = $module) =~ s/::/-/g;
-
-my $build = Module::Build->new(
- module_name => $module,
- license => 'perl',
- requires => {
- 'perl' => 5.008,
- 'constant::boolean' => 0,
- 'DateTime' => 0,
- 'Exception::Argument' => 0.05,
- 'Exception::Base' => 0.21,
- 'Exception::System' => 0.11,
- 'Moose' => 0,
- 'Sub::Exporter' => 0,
- 'Test::Assert' => 0.04,
- },
- optional => {
- },
- build_requires => {
- 'parent' => 0,
- 'Exception::Died' => 0.04,
- 'Exception::Warning' => 0.03,
- 'Test::Unit::Lite' => 0.11,
- },
- create_makefile_pl => 'traditional',
- sign => 1,
- create_readme => 1,
- create_license => 1,
- recursive_test_files => 1,
- add_to_cleanup => [
- '*.bak', '*.gz', '*.tgz', '*.ppd', '*.ppmx', '*.deb', '*.bat',
- 'Makefile', 'pm_to_blib', 'cover_db', 'Debian_CPANTS.txt',
- "$dist-*",
- ],
- meta_merge => {
- resources => {
- bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=$dist",
- repository => "http://code2.0beta.co.uk/moose/svn/$dist",
- }
- },
-);
-
-$build->create_build_script;
Copied: File-Stat-Moose/tags/0.05/trunk/Build.PL (from rev 7305, File-Stat-Moose/trunk/Build.PL)
===================================================================
--- File-Stat-Moose/tags/0.05/trunk/Build.PL (rev 0)
+++ File-Stat-Moose/tags/0.05/trunk/Build.PL 2009-01-14 12:20:43 UTC (rev 7311)
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+
+use 5.008;
+
+use strict;
+use warnings;
+
+use Module::Build;
+
+my $module = 'File::Stat::Moose';
+
+(my $dist = $module) =~ s/::/-/g;
+
+my $build = Module::Build->new(
+ module_name => $module,
+ license => 'perl',
+ requires => {
+ 'perl' => 5.008,
+ 'constant::boolean' => 0,
+ 'DateTime' => 0,
+ 'Exception::Argument' => 0.05,
+ 'Exception::Base' => 0.21,
+ 'Exception::System' => 0.11,
+ 'Moose' => 0,
+ 'Sub::Exporter' => 0,
+ 'Test::Assert' => 0.04,
+ },
+ optional => {
+ },
+ build_requires => {
+ 'parent' => 0,
+ 'Exception::Died' => 0.04,
+ 'Exception::Warning' => 0.03,
+ 'Test::Unit::Lite' => 0.11,
+ },
+ create_makefile_pl => 'traditional',
+ sign => 1,
+ create_readme => 1,
+ create_license => 1,
+ recursive_test_files => 1,
+ add_to_cleanup => [
+ '*.bak', '*.gz', '*.tgz', '*.ppd', '*.ppmx', '*.deb', '*.bat',
+ 'Makefile', 'pm_to_blib', 'cover_db', 'Debian_CPANTS.txt',
+ "$dist-*",
+ ],
+ meta_merge => {
+ resources => {
+ bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=$dist",
+ repository => "http://code2.0beta.co.uk/moose/svn/$dist",
+ }
+ },
+);
+
+$build->create_build_script;
Copied: File-Stat-Moose/tags/0.05/trunk/eg (from rev 7305, File-Stat-Moose/trunk/eg)
Copied: File-Stat-Moose/tags/0.05/trunk/lib (from rev 7305, File-Stat-Moose/trunk/lib)
Deleted: File-Stat-Moose/tags/0.05/trunk/lib/File/Stat/Moose.pm
===================================================================
--- File-Stat-Moose/trunk/lib/File/Stat/Moose.pm 2009-01-14 08:46:12 UTC (rev 7305)
+++ File-Stat-Moose/tags/0.05/trunk/lib/File/Stat/Moose.pm 2009-01-14 12:20:43 UTC (rev 7311)
@@ -1,525 +0,0 @@
-#!/usr/bin/perl -c
-
-package File::Stat::Moose;
-
-=head1 NAME
-
-File::Stat::Moose - Status info for a file - Moose-based
-
-=head1 SYNOPSIS
-
- use File::Stat::Moose;
- open my $fh, '/etc/passwd';
- $st = File::Stat::Moose->new( file => $fh );
- print "Size: ", $st->size, "\n"; # named attribute
- print "Blocks: ". $st->[12], "\n"; # numbered attribute
-
-=head1 DESCRIPTION
-
-This class provides methods that returns status info for a file. It is the
-OO-style version of stat/lstat functions. It also throws an exception
-immediately after error is occurred.
-
-=for readme stop
-
-=cut
-
-
-use 5.008;
-use strict;
-use warnings FATAL => 'all';
-
-our $VERSION = 0.05;
-
-use Moose;
-
-# Additional types
-use MooseX::Types::OpenHandle;
-use MooseX::Types::CacheFileHandle;
-
-# Run-time Assertions
-use Test::Assert ':assert';
-
-# TRUE/FALSE
-use constant::boolean;
-
-# atime, ctime, mtime attributes
-use DateTime;
-
-# file => ArrayRef[Str] attribute
-use File::Spec;
-
-
-use Exception::Base (
- '+ignore_package' => [ __PACKAGE__, qr/^File::Spec(::|$)/, 'Sub::Exporter', qr/^Moose::/, qr/^Class::MOP::/ ],
-);
-use Exception::Argument;
-use Exception::IO;
-
-
-use overload (
- '@{}' => '_deref_array',
- fallback => TRUE,
-);
-
-
-use Sub::Exporter -setup => {
- exports => [
-
- # Get file status
- stat => sub {
- sub (;*) {
- my $st = __PACKAGE__->new(
- file => (defined $_[0] ? $_[0] : $_),
- follow => TRUE,
- );
- return wantarray ? @{ $st } : $st;
- };
- },
-
- # Get link status
- lstat => sub {
- sub (;*) {
- my $st = __PACKAGE__->new(
- file => (defined $_[0] ? $_[0] : $_),
- follow => FALSE,
- );
- return wantarray ? @{ $st } : $st;
- };
- },
-
- ],
- groups => { all => [ qw{ stat lstat } ] },
-};
-
-
-# File which is checked with stat
-has file => (
- is => 'ro',
- isa => 'Str | ArrayRef[Str] | FileHandle | CacheFileHandle | OpenHandle',
- required => TRUE,
- predicate => 'has_file',
-);
-
-# Follow symlink or read symlink itself
-has follow => (
- is => 'ro',
- isa => 'Bool',
- default => FALSE,
-);
-
-# Speeds up stat on Win32
-has sloppy => (
- is => 'ro',
- isa => 'Bool',
- default => FALSE,
-);
-
-# File::Spec handler
-has spec => (
- is => 'rw',
- isa => 'ClassName',
- default => 'File::Spec',
-);
-
-# Numeric informations about a file
-has [ qw{ dev ino mode nlink uid gid rdev size blksize blocks } ] => (
- is => 'ro',
- isa => 'Maybe[Int]',
-);
-
-{
- foreach my $attr ( qw{ atime mtime ctime } ) {
-
- # Numeric informations about a file (time as unix timestamp)
- has "_${attr}_epoch" => (
- isa => 'Maybe[Int]',
- );
-
- # Time as DateTime object (lazy evaluationed)
- has $attr => (
- is => 'ro',
- isa => 'Maybe[DateTime]',
- lazy => TRUE,
- default => sub {
- defined $_[0]->{"_${attr}_epoch"}
- ? DateTime->from_epoch( epoch => $_[0]->{"_${attr}_epoch"} )
- : undef
- },
- reader => $attr,
- clearer => "_clear_$attr",
- );
-
- };
-};
-
-
-## no critic (ProhibitBuiltinHomonyms)
-## no critic (RequireArgUnpacking)
-
-# Constructor calls stat method if necessary
-sub BUILD {
- my ($self, $params) = @_;
-
- assert_not_null($self->{file}) if ASSERT;
-
- # Update stat info
- $self->stat;
-
- return TRUE;
-};
-
-
-# Call stat or lstat method
-sub stat {
- my $self = shift;
- Exception::Argument->throw( message => 'Usage: $st->stat()' ) if @_ > 0 or not blessed $self;
-
- assert_not_null($self->{file}) if ASSERT;
-
- my $file = $self->{file};
-
- # Convert array to string
- if (ref $file eq 'ARRAY') {
- $file = $self->spec->catfile(@$file);
- };
-
- # Clear lazy attributes
- delete @{$self}{ qw{ atime mtime ctime } };
-
- local ${^WIN32_SLOPPY_STAT} = $self->{sloppy};
-
- if ($self->{follow}) {
- @{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } }
- = map { defined $_ && $_ eq '' ? undef : $_ }
- CORE::stat $file or Exception::IO->throw( message => 'Cannot stat' );
- }
- else {
- no warnings 'io'; # lstat() on filehandle
- @{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } }
- = map { defined $_ && $_ eq '' ? undef : $_ }
- CORE::lstat $file or Exception::IO->throw( message => 'Cannot lstat' );
- };
-
- return $self;
-};
-
-
-# Deprecated
-sub lstat {
- my ($self) = @_;
-
- ## no critic (RequireCarping)
- warn "Method (File::Stat::Moose->lstat) is deprecated. Use method (stat).";
-
- confess "Cannot call method (File::Stat::Moose->lstat) with attribute (follow) set to false value" if not $self->follow;
-
- return $self->stat;
-};
-
-
-# Array dereference
-sub _deref_array {
- my ($self) = @_;
- return [ @{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } } ];
-};
-
-
-# Module initialization
-__PACKAGE__->meta->make_immutable();
-
-
-1;
-
-
-__END__
-
-=begin umlwiki
-
-= Component Diagram =
-
-[ <<library>> {=}
- File::Stat::Moose
- ---------------------------------
- File::Stat::Moose
- MooseX::Types::OpenHandle
- MooseX::Types::CacheFileHandle
- <<exception>> Exception::IO
- <<type>> OpenHandle
- <<type>> CacheFileHandle ]
-
-= Class Diagram =
-
-[ File::Stat::Moose
- ----------------------------------------------------------------------------------------
- +file : Str|ArrayRef[Str]|FileHandle|CacheFileHandle|OpenHandle {ro, required}
- +follow : Bool {ro}
- +sloppy : Bool {ro}
- +spec : ClassName {ro}
- +dev : Maybe[Int] {ro}
- +ino : Maybe[Int] {ro}
- +mode : Maybe[Int] {ro}
- +nlink : Maybe[Int] {ro}
- +uid : Maybe[Int] {ro}
- +gid : Maybe[Int] {ro}
- +rdev : Maybe[Int] {ro}
- +size : Maybe[Int] {ro}
- +atime : Maybe[DateTime] {ro, lazy}
- +mtime : Maybe[DateTime] {ro, lazy}
- +ctime : Maybe[DateTime] {ro, lazy}
- +blksize : Maybe[Int] {ro}
- +blocks : Maybe[Int] {ro}
- #_atime_epoch : Maybe[Int] {ro}
- #_mtime_epoch : Maybe[Int] {ro}
- #_ctime_epoch : Maybe[Int] {ro}
- ----------------------------------------------------------------------------------------
- +update() : Self
- +stat() : Self
- <<deprecated>> +lstat() : Self
- <<utility>> +stat( file : Str|ArrayRef[Str]|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
- <<utility>> +lstat( file : Str|ArrayRef[Str]|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
- -_deref_array() : ArrayRef {overload="@{}"}
- ]
-
-[File::Stat::Moose] ---> <<exception>> [Exception::Argument] [Exception::IO]
-
-=end umlwiki
-
-=head1 IMPORTS
-
-By default, the class does not export its symbols.
-
-=over
-
-=item stat
-
-=item lstat
-
-Imports C<stat> and/or C<lstat> functions.
-
- use File::Stat::Moose 'stat', 'lstat';
-
-=item :all
-
-Imports all available symbols.
-
- use File::Stat::Moose ':all';
-
-=back
-
-=head1 EXCEPTIONS
-
-=over
-
-=item Exception::Argument
-
-Thrown whether a methods is called with wrong arguments.
-
-=item Exception::IO
-
-Thrown whether an IO error is occurred.
-
-=back
-
-=head1 ATTRIBUTES
-
-=over
-
-=item file : Str|FileHandle|CacheFileHandle|OpenHandle {ro, required}
-
-Contains the file for check. The attribute can hold file name or array
-reference of path components or file handler or IO object.
-
-=item follow : Bool {ro}
-
-If the value is true and the I<file> for check is symlink, then follows it
-than checking the symlink itself.
-
-=item sloppy : Bool {ro}
-
-On Win32 L<perlfunc/stat> needs to open the file to determine the link count
-and update attributes that may have been changed through hard links. If the
-I<sloppy> is set to true value, L<perlfunc/stat> speeds up by not performing
-this operation.
-
-=item spec : ClassName {ro}
-
-Contains the name of L<File::Spec> class name which converts C<file> attribute
-from array reference to string.
-
-=item dev : Maybe[Int] {ro}
-
-ID of device containing file. If this value and following has no meaning on
-the platform, it will contain undefined value.
-
-=item ino : Maybe[Int] {ro}
-
-inode number.
-
-=item mode : Maybe[Int] {ro}
-
-Unix mode for file.
-
-=item nlink : Maybe[Int] {ro}
-
-Number of hard links.
-
-=item uid : Maybe[Int] {ro}
-
-User ID of owner.
-
-=item gid : Maybe[Int] {ro}
-
-Group ID of owner.
-
-=item rdev : Maybe[Int] {ro}
-
-Device ID (if special file).
-
-=item size : Maybe[Int] {ro}
-
-Total size, in bytes.
-
-=item atime : Maybe[DateTime] {ro}
-
-Time of last access as DateTime object.
-
-=item mtime : Maybe[DateTime] {ro}
-
-Time of last modification as DateTime object.
-
-=item ctime : Maybe[DateTime] {ro}
-
-Time of last status change as DateTime object.
-
-=item blksize : Maybe[Int] {ro}
-
-Block size for filesystem I/O.
-
-=item blocks : Maybe[Int] {ro}
-
-Number of blocks allocated.
-
-=back
-
-=head1 OVERLOADS
-
-=over
-
-=item Array dereferencing
-
-If C<File::Stat::Moose> object is dereferenced as array it returns an array
-with the same order of values as in L<perlfunc/stat> or L<perlfunc/lstat>
-functions. Attributes C<atime>, C<ctime> and C<mtime> are returned as number
-values (Unix timestamp).
-
- $st = File::Stat::Moose->new( file => '/etc/passwd' );
- @st = @$st;
-
-=back
-
-=head1 CONSTRUCTORS
-
-=over
-
-=item new( I<args> : Hash ) : Self
-
-Creates the C<File::Stat::Moose> object and calls C<update> method.
-
-If the I<file> is symlink and the I<follow> is true, it will check the file
-that it refers to. If the I<follow> is false, it will check the symlink
-itself.
-
- $st = File::Stat::Moose->new( file => '/etc/cdrom', follow => 1 );
- print "Device: ", $st->rdev, "\n"; # check real device, not symlink
-
-The object is dereferenced in array context to the array reference which
-contains the same values as L<perlfunc/stat> function output.
-
- $st = File::Stat::Moose->new( file => '/etc/passwd' );
- print "Size: ", $st->size, "\n"; # object's attribute
- print "Size: ", $st->[7], "\n"; # array dereference
-
-=back
-
-=head1 METHODS
-
-=over
-
-=item stat(I<>) : Self
-
-Updates all attributes which represent status of file.
-
-Calls L<perlfunc/stat> function if C<follow> method is true value or
-L<perlfunc/lstat> function otherwise.
-
-=back
-
-=head1 FUNCTIONS
-
-=over
-
-=item stat( I<file> : Str|ArrayRef[Str]|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
-
-Calls stat on given I<file>. If the I<file> is undefined, the C<$_> variable
-is used instead.
-
-If it is called in array context, it returns an array with the same values as
-for output of core C<stat> function.
-
- use File::Stat::Moose 'stat';
- $_ = '/etc/passwd';
- @st = stat;
- print "Size: $st[7]\n";
-
-If it is called with scalar context, it returns the C<File::Stat::Moose> object.
-
- use File::Stat::Moose 'stat';
- $st = stat '/etc/passwd';
- @st = @$st;
-
-=item lstat( I<file> : Str|ArrayRef[Str]|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
-
-It is identical to C<stat>, except that if I<file> is a symbolic link, then
-the link itself is checked, not the file that it refers to.
-
- use File::Stat::Moose 'lstat';
- @st = lstat '/etc/motd';
-
-=back
-
-=head1 BUGS
-
-C<stat> and C<lstat> functions does not accept special handler C<_> written
-as bareword. You have to use it as a glob reference C<\*_>.
-
- use File::Stat::Moose 'stat';
- stat "/etc/passwd"; # set the special filehandle _
- @st = stat _; # does not work
- @st = stat \*_; # ok
-
-=head1 PERFORMANCE
-
-The L<File::Stat::Moose> module is 1.7 times slower than L<File::stat>
-module and 10 times slower than L<perlfunc/stat> function. The function
-interface is 1.5 times slower than OO interface.
-
-=head1 SEE ALSO
-
-L<Exception::Base>, L<MooseX::Types::OpenHandle>,
-L<MooseX::Types::CacheFileHandle>, L<Moose>, L<File::stat>, L<DateTime>.
-
-=for readme continue
-
-=head1 AUTHOR
-
-Piotr Roszatycki <dexter at cpan.org>
-
-=head1 LICENSE
-
-Copyright (C) 2007, 2008, 2009 by Piotr Roszatycki <dexter at cpan.org>.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
Copied: File-Stat-Moose/tags/0.05/trunk/lib/File/Stat/Moose.pm (from rev 7307, File-Stat-Moose/trunk/lib/File/Stat/Moose.pm)
===================================================================
--- File-Stat-Moose/tags/0.05/trunk/lib/File/Stat/Moose.pm (rev 0)
+++ File-Stat-Moose/tags/0.05/trunk/lib/File/Stat/Moose.pm 2009-01-14 12:20:43 UTC (rev 7311)
@@ -0,0 +1,503 @@
+#!/usr/bin/perl -c
+
+package File::Stat::Moose;
+
+=head1 NAME
+
+File::Stat::Moose - Status info for a file - Moose-based
+
+=head1 SYNOPSIS
+
+ use File::Stat::Moose;
+ open my $fh, '/etc/passwd';
+ $st = File::Stat::Moose->new( file => $fh );
+ print "Size: ", $st->size, "\n"; # named attribute
+ print "Blocks: ". $st->[12], "\n"; # numbered attribute
+
+=head1 DESCRIPTION
+
+This class provides methods that returns status info for a file. It is the
+OO-style version of stat/lstat functions. It also throws an exception
+immediately after error is occurred.
+
+=for readme stop
+
+=cut
+
+
+use 5.008;
+use strict;
+use warnings FATAL => 'all';
+
+our $VERSION = 0.05;
+
+use Moose;
+
+# Additional types
+use MooseX::Types::OpenHandle;
+use MooseX::Types::CacheFileHandle;
+
+# Run-time Assertions
+use Test::Assert ':assert';
+
+# TRUE/FALSE
+use constant::boolean;
+
+# atime, ctime, mtime attributes
+use DateTime;
+
+
+use Exception::Base (
+ '+ignore_package' => [ __PACKAGE__, qr/^File::Spec(::|$)/, 'Sub::Exporter', qr/^Moose::/, qr/^Class::MOP::/ ],
+);
+use Exception::Argument;
+use Exception::IO;
+
+
+use overload (
+ '@{}' => '_deref_array',
+ fallback => TRUE,
+);
+
+
+use Sub::Exporter -setup => {
+ exports => [
+
+ # Get file status
+ stat => sub {
+ sub (;*) {
+ my $st = __PACKAGE__->new(
+ file => (defined $_[0] ? $_[0] : $_),
+ follow => TRUE,
+ );
+ return wantarray ? @{ $st } : $st;
+ };
+ },
+
+ # Get link status
+ lstat => sub {
+ sub (;*) {
+ my $st = __PACKAGE__->new(
+ file => (defined $_[0] ? $_[0] : $_),
+ follow => FALSE,
+ );
+ return wantarray ? @{ $st } : $st;
+ };
+ },
+
+ ],
+ groups => { all => [ qw{ stat lstat } ] },
+};
+
+
+# File which is checked with stat
+has file => (
+ is => 'ro',
+ isa => 'Str | FileHandle | CacheFileHandle | OpenHandle',
+ required => TRUE,
+ predicate => 'has_file',
+);
+
+# Follow symlink or read symlink itself
+has follow => (
+ is => 'ro',
+ isa => 'Bool',
+ default => FALSE,
+);
+
+# Speeds up stat on Win32
+has sloppy => (
+ is => 'ro',
+ isa => 'Bool',
+ default => FALSE,
+);
+
+# Numeric informations about a file
+has [ qw{ dev ino mode nlink uid gid rdev size blksize blocks } ] => (
+ is => 'ro',
+ isa => 'Maybe[Int]',
+);
+
+{
+ foreach my $attr ( qw{ atime mtime ctime } ) {
+
+ # Numeric informations about a file (time as unix timestamp)
+ has "_${attr}_epoch" => (
+ isa => 'Maybe[Int]',
+ );
+
+ # Time as DateTime object (lazy evaluationed)
+ has $attr => (
+ is => 'ro',
+ isa => 'Maybe[DateTime]',
+ lazy => TRUE,
+ default => sub {
+ defined $_[0]->{"_${attr}_epoch"}
+ ? DateTime->from_epoch( epoch => $_[0]->{"_${attr}_epoch"} )
+ : undef
+ },
+ reader => $attr,
+ clearer => "_clear_$attr",
+ );
+
+ };
+};
+
+
+## no critic (ProhibitBuiltinHomonyms)
+## no critic (RequireArgUnpacking)
+
+# Constructor calls stat method if necessary
+sub BUILD {
+ my ($self, $params) = @_;
+
+ assert_not_null($self->{file}) if ASSERT;
+
+ # Update stat info
+ $self->stat;
+
+ return TRUE;
+};
+
+
+# Call stat or lstat method
+sub stat {
+ my $self = shift;
+ Exception::Argument->throw( message => 'Usage: $st->stat()' ) if @_ > 0 or not blessed $self;
+
+ assert_not_null($self->{file}) if ASSERT;
+
+ # Clear lazy attributes
+ delete @{$self}{ qw{ atime mtime ctime } };
+
+ local ${^WIN32_SLOPPY_STAT} = $self->{sloppy};
+
+ if ($self->{follow}) {
+ @{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } }
+ = map { defined $_ && $_ eq '' ? undef : $_ }
+ CORE::stat $self->{file} or Exception::IO->throw( message => 'Cannot stat' );
+ }
+ else {
+ no warnings 'io'; # lstat() on filehandle
+ @{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } }
+ = map { defined $_ && $_ eq '' ? undef : $_ }
+ CORE::lstat $self->{file} or Exception::IO->throw( message => 'Cannot lstat' );
+ };
+
+ return $self;
+};
+
+
+# Deprecated
+sub lstat {
+ my ($self) = @_;
+
+ ## no critic (RequireCarping)
+ warn "Method (File::Stat::Moose->lstat) is deprecated. Use method (stat).";
+
+ confess "Cannot call method (File::Stat::Moose->lstat) with attribute (follow) set to false value" if not $self->follow;
+
+ return $self->stat;
+};
+
+
+# Array dereference
+sub _deref_array {
+ my ($self) = @_;
+ return [ @{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } } ];
+};
+
+
+# Module initialization
+__PACKAGE__->meta->make_immutable();
+
+
+1;
+
+
+__END__
+
+=begin umlwiki
+
+= Component Diagram =
+
+[ <<library>> {=}
+ File::Stat::Moose
+ ---------------------------------
+ File::Stat::Moose
+ MooseX::Types::OpenHandle
+ MooseX::Types::CacheFileHandle
+ <<exception>> Exception::IO
+ <<type>> OpenHandle
+ <<type>> CacheFileHandle ]
+
+= Class Diagram =
+
+[ File::Stat::Moose
+ ----------------------------------------------------------------------------------------
+ +file : Str|FileHandle|CacheFileHandle|OpenHandle {ro, required}
+ +follow : Bool {ro}
+ +sloppy : Bool {ro}
+ +dev : Maybe[Int] {ro}
+ +ino : Maybe[Int] {ro}
+ +mode : Maybe[Int] {ro}
+ +nlink : Maybe[Int] {ro}
+ +uid : Maybe[Int] {ro}
+ +gid : Maybe[Int] {ro}
+ +rdev : Maybe[Int] {ro}
+ +size : Maybe[Int] {ro}
+ +atime : Maybe[DateTime] {ro, lazy}
+ +mtime : Maybe[DateTime] {ro, lazy}
+ +ctime : Maybe[DateTime] {ro, lazy}
+ +blksize : Maybe[Int] {ro}
+ +blocks : Maybe[Int] {ro}
+ #_atime_epoch : Maybe[Int] {ro}
+ #_mtime_epoch : Maybe[Int] {ro}
+ #_ctime_epoch : Maybe[Int] {ro}
+ ----------------------------------------------------------------------------------------
+ +update() : Self
+ +stat() : Self
+ <<deprecated>> +lstat() : Self
+ <<utility>> +stat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
+ <<utility>> +lstat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
+ -_deref_array() : ArrayRef {overload="@{}"}
+ ]
+
+[File::Stat::Moose] ---> <<exception>> [Exception::Argument] [Exception::IO]
+
+=end umlwiki
+
+=head1 IMPORTS
+
+By default, the class does not export its symbols.
+
+=over
+
+=item stat
+
+=item lstat
+
+Imports C<stat> and/or C<lstat> functions.
+
+ use File::Stat::Moose 'stat', 'lstat';
+
+=item :all
+
+Imports all available symbols.
+
+ use File::Stat::Moose ':all';
+
+=back
+
+=head1 EXCEPTIONS
+
+=over
+
+=item Exception::Argument
+
+Thrown whether a methods is called with wrong arguments.
+
+=item Exception::IO
+
+Thrown whether an IO error is occurred.
+
+=back
+
+=head1 ATTRIBUTES
+
+=over
+
+=item file : Str|FileHandle|CacheFileHandle|OpenHandle {ro, required}
+
+Contains the file for check. The attribute can hold file name or file
+handler or IO object.
+
+=item follow : Bool {ro}
+
+If the value is true and the I<file> for check is symlink, then follows it
+than checking the symlink itself.
+
+=item sloppy : Bool {ro}
+
+On Win32 L<perlfunc/stat> needs to open the file to determine the link count
+and update attributes that may have been changed through hard links. If the
+I<sloppy> is set to true value, L<perlfunc/stat> speeds up by not performing
+this operation.
+
+=item dev : Maybe[Int] {ro}
+
+ID of device containing file. If this value and following has no meaning on
+the platform, it will contain undefined value.
+
+=item ino : Maybe[Int] {ro}
+
+inode number.
+
+=item mode : Maybe[Int] {ro}
+
+Unix mode for file.
+
+=item nlink : Maybe[Int] {ro}
+
+Number of hard links.
+
+=item uid : Maybe[Int] {ro}
+
+User ID of owner.
+
+=item gid : Maybe[Int] {ro}
+
+Group ID of owner.
+
+=item rdev : Maybe[Int] {ro}
+
+Device ID (if special file).
+
+=item size : Maybe[Int] {ro}
+
+Total size, in bytes.
+
+=item atime : Maybe[DateTime] {ro}
+
+Time of last access as DateTime object.
+
+=item mtime : Maybe[DateTime] {ro}
+
+Time of last modification as DateTime object.
+
+=item ctime : Maybe[DateTime] {ro}
+
+Time of last status change as DateTime object.
+
+=item blksize : Maybe[Int] {ro}
+
+Block size for filesystem I/O.
+
+=item blocks : Maybe[Int] {ro}
+
+Number of blocks allocated.
+
+=back
+
+=head1 OVERLOADS
+
+=over
+
+=item Array dereferencing
+
+If C<File::Stat::Moose> object is dereferenced as array it returns an array
+with the same order of values as in L<perlfunc/stat> or L<perlfunc/lstat>
+functions. Attributes C<atime>, C<ctime> and C<mtime> are returned as number
+values (Unix timestamp).
+
+ $st = File::Stat::Moose->new( file => '/etc/passwd' );
+ @st = @$st;
+
+=back
+
+=head1 CONSTRUCTORS
+
+=over
+
+=item new( I<args> : Hash ) : Self
+
+Creates the C<File::Stat::Moose> object and calls C<update> method.
+
+If the I<file> is symlink and the I<follow> is true, it will check the file
+that it refers to. If the I<follow> is false, it will check the symlink
+itself.
+
+ $st = File::Stat::Moose->new( file => '/etc/cdrom', follow => 1 );
+ print "Device: ", $st->rdev, "\n"; # check real device, not symlink
+
+The object is dereferenced in array context to the array reference which
+contains the same values as L<perlfunc/stat> function output.
+
+ $st = File::Stat::Moose->new( file => '/etc/passwd' );
+ print "Size: ", $st->size, "\n"; # object's attribute
+ print "Size: ", $st->[7], "\n"; # array dereference
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item stat(I<>) : Self
+
+Updates all attributes which represent status of file.
+
+Calls L<perlfunc/stat> function if C<follow> method is true value or
+L<perlfunc/lstat> function otherwise.
+
+=back
+
+=head1 FUNCTIONS
+
+=over
+
+=item stat( I<file> : Str|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
+
+Calls stat on given I<file>. If the I<file> is undefined, the C<$_> variable
+is used instead.
+
+If it is called in array context, it returns an array with the same values as
+for output of core C<stat> function.
+
+ use File::Stat::Moose 'stat';
+ $_ = '/etc/passwd';
+ @st = stat;
+ print "Size: $st[7]\n";
+
+If it is called with scalar context, it returns the C<File::Stat::Moose>
+object.
+
+ use File::Stat::Moose 'stat';
+ $st = stat '/etc/passwd';
+ @st = @$st;
+
+=item lstat( I<file> : Str|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
+
+It is identical to C<stat>, except that if I<file> is a symbolic link, then
+the link itself is checked, not the file that it refers to.
+
+ use File::Stat::Moose 'lstat';
+ @st = lstat '/etc/motd';
+
+=back
+
+=head1 BUGS
+
+C<stat> and C<lstat> functions does not accept special handler C<_> written
+as bareword. You have to use it as a glob reference C<\*_>.
+
+ use File::Stat::Moose 'stat';
+ stat "/etc/passwd"; # set the special filehandle _
+ @st = stat _; # does not work
+ @st = stat \*_; # ok
+
+=head1 PERFORMANCE
+
+The L<File::Stat::Moose> module is 1.7 times slower than L<File::stat>
+module and 10 times slower than L<perlfunc/stat> function. The function
+interface is 1.5 times slower than OO interface.
+
+=head1 SEE ALSO
+
+L<Exception::Base>, L<MooseX::Types::OpenHandle>,
+L<MooseX::Types::CacheFileHandle>, L<Moose>, L<File::stat>, L<DateTime>.
+
+=for readme continue
+
+=head1 AUTHOR
+
+Piotr Roszatycki <dexter at cpan.org>
+
+=head1 LICENSE
+
+Copyright (C) 2007, 2008, 2009 by Piotr Roszatycki <dexter at cpan.org>.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+See L<http://www.perl.com/perl/misc/Artistic.html>
Copied: File-Stat-Moose/tags/0.05/trunk/t (from rev 7305, File-Stat-Moose/trunk/t)
Deleted: File-Stat-Moose/tags/0.05/trunk/t/tlib/File/Stat/MooseTest.pm
===================================================================
--- File-Stat-Moose/trunk/t/tlib/File/Stat/MooseTest.pm 2009-01-14 08:46:12 UTC (rev 7305)
+++ File-Stat-Moose/tags/0.05/trunk/t/tlib/File/Stat/MooseTest.pm 2009-01-14 12:20:43 UTC (rev 7311)
@@ -1,172 +0,0 @@
-package File::Stat::MooseTest;
-
-use strict;
-use warnings;
-
-use Test::Unit::Lite;
-use parent 'Test::Unit::TestCase';
-
-use Test::Assert ':all';
-
-use File::Stat::Moose;
-
-use constant::boolean;
-use Exception::Base;
-
-use File::Spec;
-use File::Temp;
-
-our ($file, $symlink, $notexistant);
-
-sub set_up {
- $file = __FILE__;
- $symlink = File::Temp::tmpnam();
- $notexistant = '/MooseTestNotExistant';
-
- eval {
- symlink File::Spec->rel2abs($file), $symlink;
- };
- $symlink = undef if $@;
-};
-
-sub tear_down {
- unlink $symlink if $symlink;
-};
-
-sub test_new_file {
- my $obj = File::Stat::Moose->new( file => $file );
- assert_isa('File::Stat::Moose', $obj);
- {
- foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
- assert_matches(qr/^\d+$/, $obj->$attr, $attr) if defined $obj->$attr;
- };
- };
- {
- foreach my $attr (qw { atime mtime ctime }) {
- assert_isa('DateTime', $obj->$attr, $attr) if defined $obj->$attr;
- };
- };
- assert_not_equals(0, $obj->size);
-};
-
-sub test_new_file_sloppy {
- my $obj = File::Stat::Moose->new( file => $file, sloppy => TRUE );
- assert_isa('File::Stat::Moose', $obj);
- {
- foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
- assert_matches(qr/^\d+$/, $obj->$attr, $attr) if defined $obj->$attr;
- };
- };
- {
- foreach my $attr (qw { atime mtime ctime }) {
- assert_isa('DateTime', $obj->$attr, $attr) if defined $obj->$attr;
- };
- };
- assert_not_equals(0, $obj->size);
-};
-
-sub test_new_file_spec {
- my ($volume, $directories, $filename) = File::Spec->splitpath($file);
- my @dirs = File::Spec->splitdir($directories);
- assert_not_null($filename);
- assert_not_null(@dirs);
- assert_not_equals('', $filename);
- assert_not_equals(0, scalar @dirs);
-
- my $obj = File::Stat::Moose->new( file => [ @dirs, $filename ] );
- assert_isa('File::Stat::Moose', $obj);
- assert_not_equals(0, $obj->size);
-};
-
-sub test_new_symlink {
- return unless $symlink;
-
- my $obj1 = File::Stat::Moose->new( file => $symlink );
- assert_isa('File::Stat::Moose', $obj1);
- {
- foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
- assert_matches(qr/^\d+$/, $obj1->$attr, $attr) if defined $obj1->$attr;
- };
- };
- {
- foreach my $attr (qw { atime mtime ctime }) {
- assert_isa('DateTime', $obj1->$attr, $attr) if defined $obj1->$attr;
- };
- };
- assert_not_equals(0, $obj1->size);
-
- my $obj2 = File::Stat::Moose->new( file => $symlink, follow => 1 );
- assert_isa('File::Stat::Moose', $obj2);
- assert_not_equals(0, $obj2->size);
-
- assert_not_equals($obj1->ino, $obj2->ino);
-};
-
-sub test_new_error_args {
- assert_raises( qr/is required/, sub {
- my $obj = File::Stat::Moose->new;
- } );
-
- assert_raises( qr/does not pass the type constraint/, sub {
- my $obj = File::Stat::Moose->new( file => undef );
- } );
-
- assert_raises( qr/does not pass the type constraint/, sub {
- my $obj = File::Stat::Moose->new( file => \1 );
- } );
-
- assert_raises( qr/does not pass the type constraint/, sub {
- my $obj = File::Stat::Moose->new( file => (bless {} => 'My::Class') );
- } );
-
- assert_raises( qr/does not pass the type constraint/, sub {
- my $obj = File::Stat::Moose->new( file => $file, follow => \1 );
- } );
-};
-
-sub test_new_error_io {
- assert_raises( ['Exception::IO'], sub {
- my $obj = File::Stat::Moose->new( file => $notexistant );
- } );
-};
-
-sub test__deref_array {
- my $obj = File::Stat::Moose->new( file => $file );
- assert_isa('File::Stat::Moose', $obj);
- assert_equals(13, scalar @$obj);
- {
- foreach my $i (0..12) {
- assert_matches(qr/^\d+$/, $obj->[$i], $i) if defined $obj->[$i];
- };
- };
- assert_not_equals(0, $obj->[7]);
-};
-
-sub test_stat {
- my $file = File::Temp->new;
- assert_isa('File::Temp', $file);
- $file->autoflush(1);
- $file->print(1);
-
- my $obj = File::Stat::Moose->new( file => $file );
- assert_equals(1, $obj->size);
-
- $file->print(2);
-
- $obj->stat;
- assert_equals(2, $obj->size);
-};
-
-sub test_stat_error_args {
- my $obj = File::Stat::Moose->new( file => $file );
-
- assert_raises( ['Exception::Argument'], sub {
- File::Stat::Moose->stat;
- } );
-
- assert_raises( ['Exception::Argument'], sub {
- $obj->stat(1);
- } );
-};
-
-1;
Copied: File-Stat-Moose/tags/0.05/trunk/t/tlib/File/Stat/MooseTest.pm (from rev 7306, File-Stat-Moose/trunk/t/tlib/File/Stat/MooseTest.pm)
===================================================================
--- File-Stat-Moose/tags/0.05/trunk/t/tlib/File/Stat/MooseTest.pm (rev 0)
+++ File-Stat-Moose/tags/0.05/trunk/t/tlib/File/Stat/MooseTest.pm 2009-01-14 12:20:43 UTC (rev 7311)
@@ -0,0 +1,159 @@
+package File::Stat::MooseTest;
+
+use strict;
+use warnings;
+
+use Test::Unit::Lite;
+use parent 'Test::Unit::TestCase';
+
+use Test::Assert ':all';
+
+use File::Stat::Moose;
+
+use constant::boolean;
+use Exception::Base;
+
+use File::Spec;
+use File::Temp;
+
+our ($file, $symlink, $notexistant);
+
+sub set_up {
+ $file = __FILE__;
+ $symlink = File::Temp::tmpnam();
+ $notexistant = '/MooseTestNotExistant';
+
+ eval {
+ symlink File::Spec->rel2abs($file), $symlink;
+ };
+ $symlink = undef if $@;
+};
+
+sub tear_down {
+ unlink $symlink if $symlink;
+};
+
+sub test_new_file {
+ my $obj = File::Stat::Moose->new( file => $file );
+ assert_isa('File::Stat::Moose', $obj);
+ {
+ foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
+ assert_matches(qr/^\d+$/, $obj->$attr, $attr) if defined $obj->$attr;
+ };
+ };
+ {
+ foreach my $attr (qw { atime mtime ctime }) {
+ assert_isa('DateTime', $obj->$attr, $attr) if defined $obj->$attr;
+ };
+ };
+ assert_not_equals(0, $obj->size);
+};
+
+sub test_new_file_sloppy {
+ my $obj = File::Stat::Moose->new( file => $file, sloppy => TRUE );
+ assert_isa('File::Stat::Moose', $obj);
+ {
+ foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
+ assert_matches(qr/^\d+$/, $obj->$attr, $attr) if defined $obj->$attr;
+ };
+ };
+ {
+ foreach my $attr (qw { atime mtime ctime }) {
+ assert_isa('DateTime', $obj->$attr, $attr) if defined $obj->$attr;
+ };
+ };
+ assert_not_equals(0, $obj->size);
+};
+
+sub test_new_symlink {
+ return unless $symlink;
+
+ my $obj1 = File::Stat::Moose->new( file => $symlink );
+ assert_isa('File::Stat::Moose', $obj1);
+ {
+ foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
+ assert_matches(qr/^\d+$/, $obj1->$attr, $attr) if defined $obj1->$attr;
+ };
+ };
+ {
+ foreach my $attr (qw { atime mtime ctime }) {
+ assert_isa('DateTime', $obj1->$attr, $attr) if defined $obj1->$attr;
+ };
+ };
+ assert_not_equals(0, $obj1->size);
+
+ my $obj2 = File::Stat::Moose->new( file => $symlink, follow => 1 );
+ assert_isa('File::Stat::Moose', $obj2);
+ assert_not_equals(0, $obj2->size);
+
+ assert_not_equals($obj1->ino, $obj2->ino);
+};
+
+sub test_new_error_args {
+ assert_raises( qr/is required/, sub {
+ my $obj = File::Stat::Moose->new;
+ } );
+
+ assert_raises( qr/does not pass the type constraint/, sub {
+ my $obj = File::Stat::Moose->new( file => undef );
+ } );
+
+ assert_raises( qr/does not pass the type constraint/, sub {
+ my $obj = File::Stat::Moose->new( file => \1 );
+ } );
+
+ assert_raises( qr/does not pass the type constraint/, sub {
+ my $obj = File::Stat::Moose->new( file => (bless {} => 'My::Class') );
+ } );
+
+ assert_raises( qr/does not pass the type constraint/, sub {
+ my $obj = File::Stat::Moose->new( file => $file, follow => \1 );
+ } );
+};
+
+sub test_new_error_io {
+ assert_raises( ['Exception::IO'], sub {
+ my $obj = File::Stat::Moose->new( file => $notexistant );
+ } );
+};
+
+sub test__deref_array {
+ my $obj = File::Stat::Moose->new( file => $file );
+ assert_isa('File::Stat::Moose', $obj);
+ assert_equals(13, scalar @$obj);
+ {
+ foreach my $i (0..12) {
+ assert_matches(qr/^\d+$/, $obj->[$i], $i) if defined $obj->[$i];
+ };
+ };
+ assert_not_equals(0, $obj->[7]);
+};
+
+sub test_stat {
+ my $file = File::Temp->new;
+ assert_isa('File::Temp', $file);
+ $file->autoflush(1);
+ $file->print(1);
+
+ my $obj = File::Stat::Moose->new( file => $file );
+ assert_equals(1, $obj->size);
+
+ $file->print(2);
+
+ $obj->stat;
+ assert_equals(2, $obj->size);
+};
+
+sub test_stat_error_args {
+ my $obj = File::Stat::Moose->new( file => $file );
+
+ assert_raises( ['Exception::Argument'], sub {
+ File::Stat::Moose->stat;
+ } );
+
+ assert_raises( ['Exception::Argument'], sub {
+ $obj->stat(1);
+ } );
+};
+
+1;
Copied: File-Stat-Moose/tags/0.05/trunk/xt (from rev 7305, File-Stat-Moose/trunk/xt)
Deleted: File-Stat-Moose/tags/0.05/trunk/xt/distribution.t
===================================================================
--- File-Stat-Moose/trunk/xt/distribution.t 2009-01-14 08:46:12 UTC (rev 7305)
+++ File-Stat-Moose/tags/0.05/trunk/xt/distribution.t 2009-01-14 12:20:43 UTC (rev 7311)
@@ -1,10 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-our $VERSION = '0.999_001';
-
-# No POD coverage due to complaints about builtins when using Fatal.
-use Test::Distribution ();
-Test::Distribution->import( distversion => 1, not => 'podcover' );
Copied: File-Stat-Moose/tags/0.05/trunk/xt/distribution.t (from rev 7309, File-Stat-Moose/trunk/xt/distribution.t)
===================================================================
--- File-Stat-Moose/tags/0.05/trunk/xt/distribution.t (rev 0)
+++ File-Stat-Moose/tags/0.05/trunk/xt/distribution.t 2009-01-14 12:20:43 UTC (rev 7311)
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+our $VERSION = '0.999_001';
+
+# No POD coverage due to complaints about builtins when using Fatal.
+use Test::Distribution ();
+Test::Distribution->import( distversion => 1, not => [ 'pod', 'podcover', 'prereq' ] );
More information about the Moose-commits
mailing list