[Moose-commits] r7193 - in File-Stat-Moose/trunk: . eg lib
lib/Exception lib/File/Stat lib/MooseX/Types t t/tlib/File/Stat xt
dexter at code2.0beta.co.uk
dexter at code2.0beta.co.uk
Mon Dec 29 22:04:46 GMT 2008
Author: dexter
Date: 2008-12-29 14:04:45 -0800 (Mon, 29 Dec 2008)
New Revision: 7193
Added:
File-Stat-Moose/trunk/eg/stat.pl
File-Stat-Moose/trunk/lib/Exception/
File-Stat-Moose/trunk/lib/Exception/IO.pm
File-Stat-Moose/trunk/xt/benchmark.pl
File-Stat-Moose/trunk/xt/cover.sh
File-Stat-Moose/trunk/xt/pod_syntax.t
File-Stat-Moose/trunk/xt/profile.pl
File-Stat-Moose/trunk/xt/trace.pl
Removed:
File-Stat-Moose/trunk/eg/stat_passwd.pl
File-Stat-Moose/trunk/t/benchmark.pl
File-Stat-Moose/trunk/t/cover.sh
File-Stat-Moose/trunk/t/profile.pl
File-Stat-Moose/trunk/xt/pod.t
Modified:
File-Stat-Moose/trunk/Build.PL
File-Stat-Moose/trunk/Changes
File-Stat-Moose/trunk/Incompatibilities
File-Stat-Moose/trunk/MANIFEST
File-Stat-Moose/trunk/MANIFEST.SKIP
File-Stat-Moose/trunk/lib/File/Stat/Moose.pm
File-Stat-Moose/trunk/lib/MooseX/Types/CacheFileHandle.pm
File-Stat-Moose/trunk/lib/MooseX/Types/OpenHandle.pm
File-Stat-Moose/trunk/t/all_tests.t
File-Stat-Moose/trunk/t/test.pl
File-Stat-Moose/trunk/t/tlib/File/Stat/MooseFunctionTest.pm
File-Stat-Moose/trunk/t/tlib/File/Stat/MooseTest.pm
File-Stat-Moose/trunk/xt/pod_coverage.t
Log:
* New attribute "sloppy" for Win32.
* Static methods "stat" and "lstat" was removed.
* If some attributes have no meaning on platform, they contain undefined
value.
* Exception::IO was moved to separate package.
* Requires constant::boolean, Exception::Argument.
* Build requires parent.
* Fixed incompatibility for Win32 in test units.
Modified: File-Stat-Moose/trunk/Build.PL
===================================================================
--- File-Stat-Moose/trunk/Build.PL 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/Build.PL 2008-12-29 22:04:45 UTC (rev 7193)
@@ -10,20 +10,23 @@
dist_author => 'Piotr Roszatycki <dexter at debian.org>',
license => 'perl',
requires => {
- 'perl' => 5.008,
- 'DateTime' => 0,
- 'Exception::Base' => 0.20,
- 'Exception::System' => 0.11,
- 'Moose' => 0,
- 'Sub::Exporter' => 0,
+ 'perl' => 5.008,
+ 'constant::boolean' => 0,
+ 'DateTime' => 0,
+ 'Exception::Argument' => 0,
+ 'Exception::Base' => 0.20,
+ 'Exception::System' => 0.11,
+ 'Moose' => 0,
+ 'Sub::Exporter' => 0,
},
optional => {
},
build_requires => {
- 'Exception::Died' => 0.04,
- 'Exception::Warning' => 0.03,
- 'Test::Assert' => 0,
- 'Test::Unit::Lite' => 0.10,
+ 'parent' => 0,
+ 'Exception::Died' => 0.04,
+ 'Exception::Warning' => 0.03,
+ 'Test::Assert' => 0,
+ 'Test::Unit::Lite' => 0.10,
},
create_makefile_pl => 'traditional',
create_readme => 1,
Modified: File-Stat-Moose/trunk/Changes
===================================================================
--- File-Stat-Moose/trunk/Changes 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/Changes 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,4 +1,21 @@
------------------------------------------------------------------------
+0.04 | Piotr Roszatycki <dexter at debian.org> | 2008-12-27
+
+Changes:
+
+* New attribute "sloppy" for Win32.
+* Static methods "stat" and "lstat" was removed.
+* If some attributes have no meaning on platform, they contain undefined
+ value.
+* Exception::IO was moved to separate package.
+* Requires constant::boolean, Exception::Argument.
+* Build requires parent.
+
+Fixes:
+
+* Fixed incompatibility for Win32 in test units.
+
+------------------------------------------------------------------------
0.03 | Piotr Roszatycki <dexter at debian.org> | 2008-12-08
Changes:
Modified: File-Stat-Moose/trunk/Incompatibilities
===================================================================
--- File-Stat-Moose/trunk/Incompatibilities 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/Incompatibilities 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,38 +1,29 @@
-0.02 -> 0.03
+------------------------------------------------------------------------
+0.03 -> 0.04
-* Accessors "mtime", "atime" and "ctime" return DateTime object.
+* Static methods "stat" and "lstat" was removed.
Was:
-
- my $st = File::Stat::Moose->new(file => "/etc/passwd");
- my $mtime = $st->mtime;
- print $mtime;
-
+
+ my $st1 = File::Stat::Moose->stat( "/etc/passwd" );
+ my $st2 = File::Stat::Moose->lstat( "/dev/cdrom" );
+
Should be:
+
+ my $st1 = File::Stat::Moose->new( file => "/etc/passwd", follow => 1 );
+ my $st2 = File::Stat::Moose->new( file => "/dev/cdrom" );
- my $st = File::Stat::Moose->new(file => "/etc/passwd");
- my $mtime = $st->mtime;
- print $mtime->epoch;
+* If some attributes have no meaning on platform, they contain undefined
+ value.
-* File is an argument for "stat" and "lstat" static methods only.
-
Was:
- my $st = File::Stat::Moose->new;
- $st->stat("/etc/passwd");
-
- Should be:
+ my $st = File::Stat::Moose->new( 'C:\Autoexec.bat' );
+ assert_str_equals( '', $st->blksize );
- my $st = File::Stat::Moose->new;
- $st->file("/etc/passwd");
- $st->stat;
+ Should be:
- or:
-
- my $st = File::Stat::Moose->stat("/etc/passwd");
+ my $st = File::Stat::Moose->new( 'C:\Autoexec.bat' );
+ assert_null( $st->blksize );
- or:
-
- my $st = File::Stat::Moose->new(file => "/etc/passwd");
-
------------------------------------------------------------------------
Modified: File-Stat-Moose/trunk/MANIFEST
===================================================================
--- File-Stat-Moose/trunk/MANIFEST 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/MANIFEST 2008-12-29 22:04:45 UTC (rev 7193)
@@ -2,6 +2,7 @@
Changes
eg/stat_passwd.pl
Incompatibilities
+lib/Exception/IO.pm
lib/File/Stat/Moose.pm
lib/MooseX/Types/CacheFileHandle.pm
lib/MooseX/Types/OpenHandle.pm
@@ -11,15 +12,20 @@
META.yml
README
t/all_tests.t
-t/benchmark.pl
-t/cover.sh
-t/profile.pl
t/test.pl
t/tlib/File/Stat/MooseFunctionTest.pm
t/tlib/File/Stat/MooseTest.pm
+xt/benchmark.pl
+xt/consistent_version_numbers.t
+xt/copyright.t
+xt/cover.sh
+xt/distribution.t
xt/kwalitee.t
xt/minimumversion.t
xt/perlcritic.t
xt/perlcriticrc
-xt/pod.t
xt/pod_coverage.t
+xt/pod_spell.xt
+xt/pod_syntax.t
+xt/profile.pl
+xt/trace.pl
Modified: File-Stat-Moose/trunk/MANIFEST.SKIP
===================================================================
--- File-Stat-Moose/trunk/MANIFEST.SKIP 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/MANIFEST.SKIP 2008-12-29 22:04:45 UTC (rev 7193)
@@ -19,6 +19,7 @@
# Avoid Devel::Cover generated files
\bcover_db
+\btmon.out$
# Avoid temp and backup files.
~$
@@ -28,6 +29,7 @@
\#$
\.#
\.rej$
+\.diff$
# Avoid OS-specific files/dirs
# Mac OSX metadata
Copied: File-Stat-Moose/trunk/eg/stat.pl (from rev 7088, File-Stat-Moose/trunk/eg/stat_passwd.pl)
===================================================================
--- File-Stat-Moose/trunk/eg/stat.pl (rev 0)
+++ File-Stat-Moose/trunk/eg/stat.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -I../lib
+
+use strict;
+
+use File::Stat::Moose;
+
+-f $ARGV[0] or die "Usage: $0 filename\n";
+my $st = File::Stat::Moose->new( file => \*_ );
+
+print "Size: ", $st->size, "\n"; # named field
+print "Blocks: ". $st->[12], "\n"; # numbered field
+
+print $st->dump;
Deleted: File-Stat-Moose/trunk/eg/stat_passwd.pl
===================================================================
--- File-Stat-Moose/trunk/eg/stat_passwd.pl 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/eg/stat_passwd.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,12 +0,0 @@
-#!/usr/bin/perl -I../lib
-
-use IO::File;
-use File::Stat::Moose;
-
-$fh = IO::File->new( $ARGV[0] || die "Usage: $0 filename\n" );
-$st = File::Stat::Moose->new( file=>$fh );
-
-print "Size: ", $st->size, "\n"; # named field
-print "Blocks: ". $st->[12], "\n"; # numbered field
-
-print $st->dump;
Added: File-Stat-Moose/trunk/lib/Exception/IO.pm
===================================================================
--- File-Stat-Moose/trunk/lib/Exception/IO.pm (rev 0)
+++ File-Stat-Moose/trunk/lib/Exception/IO.pm 2008-12-29 22:04:45 UTC (rev 7193)
@@ -0,0 +1,112 @@
+#!/usr/bin/perl -c
+
+package Exception::IO;
+
+=head1 NAME
+
+Exception::IO - Thrown when IO operation failed
+
+=head1 SYNOPSIS
+
+ use warnings FATAL => 'all';
+ use Exception::Fatal;
+ use Exception::IO;
+
+ my $status = eval {
+ open my $fh, '/etc/passwd', '+badmode';
+ };
+ if ($@ or not defined $status) {
+ my $e = $@ ? Exception::Fatal->catch : Exception::IO->new;
+ $e->throw( message => 'Cannot open' );
+ };
+
+=head1 DESCRIPTION
+
+This class is an L<Exception::System> exception thrown when IO operation
+failed.
+
+=for readme stop
+
+=cut
+
+use 5.006;
+use strict;
+use warnings;
+
+our $VERSION = 0.04;
+
+
+use Exception::Base 0.21 (
+ 'Exception::IO' => {
+ isa => 'Exception::System',
+ message => 'Unknown IO exception',
+ },
+);
+
+
+1;
+
+
+__END__
+
+=begin umlwiki
+
+= Class Diagram =
+
+[ <<exception>>
+ Exception::IO
+ -------------------------------------------------
+ +message : Str = "Unknown IO exception" {rw, new}
+ -------------------------------------------------
+ ]
+
+[Exception::IO] ---|> [Exception::System]
+
+=end umlwiki
+
+=head1 BASE CLASSES
+
+=over
+
+=item *
+
+L<Exception::System>
+
+=back
+
+=head1 ATTRIBUTES
+
+This class provides new attributes. See L<Exception::Base> for other
+descriptions.
+
+=over
+
+=item message : Str = "Unknown IO exception" {rw}
+
+Contains the message of the exception. This class overrides the default value
+from L<Exception::Base> class.
+
+=back
+
+=head1 SEE ALSO
+
+L<Exception::System>, L<Exception::Base>.
+
+=head1 BUGS
+
+If you find the bug, please report it.
+
+=for readme continue
+
+=head1 AUTHOR
+
+Piotr Roszatycki E<lt>dexter at debian.orgE<gt>
+
+=head1 LICENSE
+
+Copyright (C) 2008 by Piotr Roszatycki E<lt>dexter at debian.orgE<gt>.
+
+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>
Modified: File-Stat-Moose/trunk/lib/File/Stat/Moose.pm
===================================================================
--- File-Stat-Moose/trunk/lib/File/Stat/Moose.pm 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/lib/File/Stat/Moose.pm 2008-12-29 22:04:45 UTC (rev 7193)
@@ -29,61 +29,23 @@
use strict;
use warnings;
-our $VERSION = 0.03;
+our $VERSION = 0.04;
use Moose;
use MooseX::Types::OpenHandle;
use MooseX::Types::CacheFileHandle;
+use constant::boolean;
use Scalar::Util 'weaken';
use DateTime;
-# File which is checked with stat
-has file => (
- is => 'rw',
- isa => 'Str | FileHandle | CacheFileHandle | OpenHandle',
-);
-
-# Follow symlink or read symlink itself
-has follow => (
- is => 'rw',
- isa => 'Bool',
-);
-
-# Numeric informations about a file
-has [ qw{ dev ino mode nlink uid gid rdev size blksize blocks } ] => (
- is => 'ro',
- isa => 'Int',
-);
-
-{
- foreach my $attr ( qw{ atime mtime ctime } ) {
-
- # Numeric informations about a file (time as unix timestamp)
- has "_${attr}_epoch" => (
- isa => 'Int',
- );
-
- # Time as DateTime object (lazy evaluationed)
- has $attr => (
- is => 'ro',
- isa => 'DateTime',
- lazy => 1,
- default => sub { DateTime->from_epoch( epoch => $_[0]->{"_${attr}_epoch"} ) },
- reader => $attr,
- );
-
- };
-};
-
-
use Exception::Base (
'+ignore_package' => [ __PACKAGE__, 'Sub::Exporter', qr/^Moose::/, qr/^Class::MOP::/ ],
- 'Exception::Argument' => { isa => 'Exception::Base' },
- 'Exception::IO' => { isa => 'Exception::System' },
);
+use Exception::Argument;
+use Exception::IO;
use overload (
@@ -121,6 +83,58 @@
};
+# File which is checked with stat
+has file => (
+ is => 'rw',
+ isa => 'Str | FileHandle | CacheFileHandle | OpenHandle',
+);
+
+# Follow symlink or read symlink itself
+has follow => (
+ is => 'rw',
+ isa => 'Bool',
+ default => FALSE,
+);
+
+# Speeds up stat on Win32
+has sloppy => (
+ is => 'rw',
+ 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 => 1,
+ default => sub {
+ return '' if not exists $_[0]->{"_${attr}_epoch"};
+ defined $_[0]->{"_${attr}_epoch"}
+ ? DateTime->from_epoch( epoch => $_[0]->{"_${attr}_epoch"} )
+ : undef
+ },
+ reader => $attr,
+ );
+
+ };
+};
+
+
# Constructor calls stat method if necessary
sub BUILD {
my ($self, $params) = @_;
@@ -138,52 +152,46 @@
sub stat {
my ($self, $file) = @_;
- # Called as static method
- if (not ref $self) {
- Exception::Argument->throw( message => 'Usage: ' . __PACKAGE__ . '->lstat(FILE)' ) if @_ != 2;
- return $self->new( file => $file, follow => 1 );
- };
-
Exception::Argument->throw( message => 'Usage: $st->stat()' ) if @_ > 1;
# Clean lazy attributes
delete @{$self}{ qw{ atime mtime ctime } };
+ local ${^WIN32_SLOPPY_STAT} = $self->{sloppy};
+
@{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } }
- = CORE::stat $self->{file} or Exception::IO->throw( message => 'Cannot stat' );
+ = map { defined $_ && $_ eq '' ? undef : $_ }
+ CORE::stat $self->{file} or Exception::IO->throw( message => 'Cannot stat' );
return $self;
-}
+};
# Get link status
sub lstat {
my ($self, $file) = @_;
- # Called as static method
- if (not ref $self) {
- Exception::Argument->throw( message => 'Usage: ' . __PACKAGE__ . '->lstat(FILE)' ) if @_ != 2;
- return $self->new( file => $file );
- };
-
Exception::Argument->throw( message => 'Usage: $st->lstat()' ) if @_ > 1;
# Clean lazy attributes
delete @{$self}{ qw{ atime mtime ctime } };
+ local ${^WIN32_SLOPPY_STAT} = $self->{sloppy};
+
no warnings 'io'; # lstat() on filehandle
@{$self}{ qw{ dev ino mode nlink uid gid rdev size _atime_epoch _mtime_epoch _ctime_epoch blksize blocks } }
- = CORE::lstat $self->{file} or Exception::IO->throw( message => 'Cannot lstat' );
+ = map { defined $_ && $_ eq '' ? undef : $_ }
+ CORE::lstat $self->{file} or Exception::IO->throw( message => 'Cannot lstat' );
return $self;
-}
+};
# 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
@@ -205,58 +213,61 @@
File::Stat::Moose
MooseX::Types::OpenHandle
MooseX::Types::CacheFileHandle
- Exception::IO <<exception>>
- Exception::Argument <<exception>>
- OpenHandle <<type>
- CacheFileHandle <<type>> ]
+ <<exception>> Exception::IO
+ <<type>> OpenHandle
+ <<type>> CacheFileHandle ]
-[File::Stat::Moose {=}] ---> <<use>> [Exception::Base {=}] [Sub::Exporter {=}] [overload {=}]
+= Class Diagram =
-[File::Stat::Moose {=}] ---> <<use>> [Moose {=}]
+[ File::Stat::Moose
+ ----------------------------------------------------------------------------------------
+ +file : Str|FileHandle|CacheFileHandle|OpenHandle {rw}
+ +follow : Bool {rw}
+ +sloppy : Bool {rw}
+ +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}
+ ----------------------------------------------------------------------------------------
+ +stat() : Self
+ +lstat() : Self
+ <<utility>> +stat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
+ <<utility>> +lstat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
+ -_deref_array() : ArrayRef {overload="@{}"}
+ ]
-[MooseX::Types::OpenHandle {=}] ---> <<use>> [Moose::Util::TypeConstraints {=}]
+[File::Stat::Moose] ---> <<exception>> [Exception::Argument] [Exception::IO]
-[MooseX::Types::CacheFileHandle {=}] ---> <<use>> [Moose::Util::TypeConstraints {=}]
+=end umlwiki
-[<<exception>> Exception::IO] ---|> [<<exception>> Exception::System]
+=head1 IMPORTS
-[<<exception>> Exception::Argument] ---|> [<<exception>> Exception::Base]
+By default, the class does not export its symbols.
-[<<type>> OpenHandle] ---|> [<<type>> Ref]
+=over
-[<<type>> CacheFileHandle] ---|> [<<type>> GlobRef]
+=item use File::Stat::Moose 'stat', 'lstat';
-= Class Diagram =
+Imports C<stat> and/or C<lstat> functions.
-[ File::Stat::Moose
- ---------------------------------------------------------------------------
- +file : Str|FileHandle|CacheFileHandle|OpenHandle {new}
- +follow : Bool {new}
- +dev : Int
- +ino : Int
- +mode : Int
- +nlink : Int
- +uid : Int
- +gid : Int
- +rdev : Int
- +size : Int
- +atime : DateTime {lazy}
- +mtime : DateTime {lazy}
- +ctime : DateTime {lazy}
- +blksize : Int
- +blocks : Int
- #_atime_epoch : Int
- #_mtime_epoch : Int
- #_ctime_epoch : Int
- ---------------------------------------------------------------------------
- +stat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ )
- +lstat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ )
- <<utility>> +stat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ )
- <<utility>> +lstat( file : Str|FileHandle|CacheFileHandle|OpenHandle = $_ )
- -_deref_array() : ArrayRef {overload="@{}"} ]
+=item use File::Stat::Moose ':all';
-=end umlwiki
+Imports all available symbols.
+=back
+
=head1 EXCEPTIONS
=over
@@ -271,95 +282,104 @@
=back
-=head1 IMPORTS
-
-By default, the class does not export its symbols.
-
-=over
-
-=item use File::Stat::Moose 'stat', 'lstat';
-
-Imports C<stat> and/or C<lstat> functions.
-
-=item use File::Stat::Moose ':all';
-
-Imports all available symbols.
-
-=back
-
=head1 ATTRIBUTES
=over
-=item file (rw, new)
+=item file : Str|FileHandle|CacheFileHandle|OpenHandle {rw}
Contains the file for check. The attribute can hold file name or file handler
or IO object.
-=item follow (rw, new)
+=item follow : Bool {rw}
-If the value is true and the I<file> for check is symlink, then follow it
+If the value is true and the I<file> for check is symlink, then follows it
than checking the symlink itself.
-=item dev (ro)
+=item sloppy : Bool {rw}
-ID of device containing file.
+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 ino (ro)
+=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 (ro)
+=item mode : Maybe[Int] {ro}
Unix mode for file.
-=item nlink (ro)
+=item nlink : Maybe[Int] {ro}
Number of hard links.
-=item uid (ro)
+=item uid : Maybe[Int] {ro}
User ID of owner.
-=item gid (ro)
+=item gid : Maybe[Int] {ro}
Group ID of owner.
-=item rdev (ro)
+=item rdev : Maybe[Int] {ro}
Device ID (if special file).
-=item size (ro)
+=item size : Maybe[Int] {ro}
Total size, in bytes.
-=item atime (ro)
+=item atime : Maybe[DateTime] {ro}
Time of last access as DateTime object.
-=item mtime (ro)
+=item mtime : Maybe[DateTime] {ro}
Time of last modification as DateTime object.
-=item ctime (ro)
+=item ctime : Maybe[DateTime] {ro}
Time of last status change as DateTime object.
-=item blksize (ro)
+=item blksize : Maybe[Int] {ro}
-Blocksize for filesystem I/O.
+Block size for filesystem I/O.
-=item blocks (ro)
+=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;
+ $st->file( '/etc/passwd' );
+ @st = @$st;
+
+=back
+
=head1 CONSTRUCTORS
=over
-=item new
+=item new( I<args> : Hash ) : Self
Creates the C<File::Stat::Moose> object.
@@ -385,40 +405,22 @@
print "Size: ", $st->size, "\n"; # object's attribute
print "Size: ", $st->[7], "\n"; # array dereference
-=item File::Stat::Moose->stat(I<file>)
-
-Creates the C<File::Stat::Moose> object and calls L<perlfunc/stat> function on
-given I<file>. If the I<file> is undefined, the <$_> variable is used
-instead. It returns the object reference.
-
- $st = File::Stat::Moose->stat( '/etc/passwd' );
- print "Size: ", $st->size, "\n";
- @st = @{ File::Stat::Moose->stat( '/etc/passwd' ) };
-
-=item File::Stat::Moose->lstat(I<file>)
-
-Creates the C<File::Stat::Moose> object and calls L<perlfunc/lstat> function on
-given I<file>. If the I<file> is undefined, the <$_> variable is used
-instead. It returns the object reference.
-
- @st = @{ File::Stat::Moose->lstat( '/dev/stdin' ) };
-
=back
=head1 METHODS
=over
-=item $st->stat
+=item stat(I<>) : Self
-Calls stat on the file which has beed set with C<new> constructor. It returns
+Calls stat on the file which has been set with C<new> constructor. It returns
the object reference.
$st = File::Stat::Moose->new;
$st->file( '/etc/passwd' );
print "Size: ", $st->stat->size, "\n";
-=item $st->lstat
+=item lstat(I<>) : Self
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.
@@ -433,26 +435,26 @@
=over
-=item stat([I<file>])
+=item stat( I<file> : Str|FileHandle|CacheFileHandle|OpenHandle = $_ ) : Self|Array
-Calls stat on given I<file>. If the I<file> is undefined, the <$_> variable
+Calls stat on given I<file>. If the I<file> is undefined, the C<$_> variable
is used instead.
-If it is called as function or static method in array context, it returns an
-array with the same values as for output of core C<stat> function.
+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 File::Stat::Moose object.
+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>])
+=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.
Modified: File-Stat-Moose/trunk/lib/MooseX/Types/CacheFileHandle.pm
===================================================================
--- File-Stat-Moose/trunk/lib/MooseX/Types/CacheFileHandle.pm 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/lib/MooseX/Types/CacheFileHandle.pm 2008-12-29 22:04:45 UTC (rev 7193)
@@ -24,23 +24,29 @@
=cut
+use 5.008;
use strict;
use warnings;
-our $VERSION = 0.03;
+our $VERSION = 0.04;
use Moose::Util::TypeConstraints;
-subtype 'CacheFileHandle'
- => as 'GlobRef'
- => where { defined Scalar::Util::reftype($_)
- && Scalar::Util::reftype($_) eq 'GLOB'
- && $_ == \*_ }
- => optimize_as { defined $_[0]
- && defined Scalar::Util::reftype($_[0])
- && Scalar::Util::reftype($_[0]) eq 'GLOB'
- && $_[0] == \*_ };
+subtype CacheFileHandle => (
+ as 'GlobRef',
+ where {
+ defined Scalar::Util::reftype($_)
+ && Scalar::Util::reftype($_) eq 'GLOB'
+ && $_ == \*_
+ },
+ optimize_as {
+ defined $_[0]
+ && defined Scalar::Util::reftype($_[0])
+ && Scalar::Util::reftype($_[0]) eq 'GLOB'
+ && $_[0] == \*_
+ },
+);
1;
Modified: File-Stat-Moose/trunk/lib/MooseX/Types/OpenHandle.pm
===================================================================
--- File-Stat-Moose/trunk/lib/MooseX/Types/OpenHandle.pm 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/lib/MooseX/Types/OpenHandle.pm 2008-12-29 22:04:45 UTC (rev 7193)
@@ -28,23 +28,29 @@
=cut
+use 5.008;
use strict;
use warnings;
-our $VERSION = 0.03;
+our $VERSION = 0.04;
use Moose::Util::TypeConstraints;
-subtype 'OpenHandle'
- => as 'Ref'
- => where { defined Scalar::Util::reftype($_)
- && Scalar::Util::reftype($_) eq 'GLOB'
- && Scalar::Util::openhandle($_) }
- => optimize_as { defined $_[0]
- && defined Scalar::Util::reftype($_[0])
- && Scalar::Util::reftype($_[0]) eq 'GLOB'
- && Scalar::Util::openhandle($_[0]) };
+subtype OpenHandle => (
+ as 'Ref',
+ where {
+ defined Scalar::Util::reftype($_)
+ && Scalar::Util::reftype($_) eq 'GLOB'
+ && Scalar::Util::openhandle($_)
+ },
+ optimize_as {
+ defined $_[0]
+ && defined Scalar::Util::reftype($_[0])
+ && Scalar::Util::reftype($_[0]) eq 'GLOB'
+ && Scalar::Util::openhandle($_[0])
+ },
+);
1;
Modified: File-Stat-Moose/trunk/t/all_tests.t
===================================================================
--- File-Stat-Moose/trunk/t/all_tests.t 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/t/all_tests.t 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,25 +1,15 @@
#!/usr/bin/perl
+use 5.008;
use strict;
use warnings;
-use File::Spec;
-use Cwd;
+use Test::Unit::Lite 0.10;
+use Test::Assert;
-BEGIN {
- unshift @INC, map { /(.*)/; $1 } split(/:/, $ENV{PERL5LIB}) if defined $ENV{PERL5LIB} and ${^TAINT};
+use Exception::Base max_arg_nums => 0, max_arg_len => 200, verbosity => 4;
+use Exception::Warning '%SIG' => 'die', verbosity => 4;
+use Exception::Died '%SIG', verbosity => 4;
+use Exception::Assertion verbosity => 4;
- my $cwd = ${^TAINT} ? do { local $_=getcwd; /(.*)/; $1 } : '.';
- unshift @INC, File::Spec->catdir($cwd, 'inc');
- unshift @INC, File::Spec->catdir($cwd, 'lib');
-}
-
-use Test::Unit::Lite;
-
-use Exception::Base
- max_arg_nums => 0, max_arg_len => 200, verbosity => 3,
- '+ignore_package' => [ qr/^Test::Unit::/, 'main' ];
-use Exception::Warning '%SIG' => 'die';
-use Exception::Died '%SIG' => 'die';
-
Test::Unit::HarnessUnit->new->start('Test::Unit::Lite::AllTests');
Deleted: File-Stat-Moose/trunk/t/benchmark.pl
===================================================================
--- File-Stat-Moose/trunk/t/benchmark.pl 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/t/benchmark.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,51 +0,0 @@
-#!/usr/bin/perl -al
-
-use lib 'lib', '../lib';
-
-package My::CoreStat;
-our $n = 0;
-sub test {
- my $size = (stat '/etc/passwd')[7];
- $n++;
-}
-
-
-package My::FileStat;
-use File::stat;
-our $n = 0;
-sub test {
- my $st = stat '/etc/passwd';
- my $size = $st->size;
- $n++;
-}
-
-
-package My::FileStatMoose;
-use File::Stat::Moose;
-our $n = 0;
-sub test {
- my $size = File::Stat::Moose->new(file=>'/etc/passwd')->size;
- $n++;
-}
-
-
-package My::FileStatMooseFunc;
-use File::Stat::Moose 'stat';
-our $n = 0;
-sub test {
- my $size = (stat '/etc/passwd')[7];
- $n++;
-}
-
-package main;
-
-use Benchmark ':all';
-
-my $result = timethese($ARGV[0] || -1, {
- '1_CoreStat' => sub { My::CoreStat::test; },
- '2_FileStat' => sub { My::FileStat::test; },
- '3_FileStatMoose' => sub { My::FileStatMoose::test; },
- '4_FileStatMooseFunc' => sub { My::FileStatMooseFunc::test; },
-});
-
-cmpthese($result);
Deleted: File-Stat-Moose/trunk/t/cover.sh
===================================================================
--- File-Stat-Moose/trunk/t/cover.sh 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/t/cover.sh 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,6 +0,0 @@
-cd $(dirname $0)
-cd ..
-perl Build.PL
-cover -delete
-HARNESS_PERL_SWITCHES=-MDevel::Cover ./Build test
-cover
Deleted: File-Stat-Moose/trunk/t/profile.pl
===================================================================
--- File-Stat-Moose/trunk/t/profile.pl 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/t/profile.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,11 +0,0 @@
-#!/usr/bin/perl -d:DProf
-
-use lib 'lib', '../lib';
-use File::Stat::Moose;
-
-
-foreach (1..10000) {
- my $size = File::Stat::Moose->new(file=>'/etc/passwd')->mtime;
-}
-
-print "tmon.out data collected. Call dprofpp\n";
Modified: File-Stat-Moose/trunk/t/test.pl
===================================================================
--- File-Stat-Moose/trunk/t/test.pl 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/t/test.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,5 +1,6 @@
#!/usr/bin/perl
+use 5.008;
use strict;
use warnings;
@@ -18,12 +19,12 @@
unshift @INC, File::Spec->catdir($cwd, 'lib');
}
-use Test::Unit::Lite;
+use Test::Unit::Lite 0.10;
+use Test::Assert;
-use Exception::Base
- max_arg_nums => 0, max_arg_len => 200, verbosity => 4,
- '+ignore_package' => [ qr/^Test::Unit::/, 'main' ];
-use Exception::Warning '%SIG' => 'die';
-use Exception::Died '%SIG' => 'die';
+use Exception::Base max_arg_nums => 0, max_arg_len => 200, verbosity => 4;
+use Exception::Warning '%SIG' => 'die', verbosity => 4;
+use Exception::Died '%SIG', verbosity => 4;
+use Exception::Assertion verbosity => 4;
all_tests;
Modified: File-Stat-Moose/trunk/t/tlib/File/Stat/MooseFunctionTest.pm
===================================================================
--- File-Stat-Moose/trunk/t/tlib/File/Stat/MooseFunctionTest.pm 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/t/tlib/File/Stat/MooseFunctionTest.pm 2008-12-29 22:04:45 UTC (rev 7193)
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use base 'Test::Unit::TestCase';
+use parent 'Test::Unit::TestCase';
use Test::Assert ':all';
use File::Stat::Moose ':all';
@@ -11,7 +11,7 @@
use Exception::Base;
use File::Spec;
-use File::Temp ();
+use File::Temp;
{
package File::Stat::MooseFunctionTest::Test1;
@@ -43,8 +43,6 @@
};
sub test_import {
- my $self = shift;
-
assert_not_null(prototype 'File::Stat::MooseFunctionTest::stat');
assert_not_null(prototype 'File::Stat::MooseFunctionTest::lstat');
@@ -56,10 +54,9 @@
};
sub test_stat {
- my $self = shift;
-
my $scalar = stat($file);
- assert_not_null($scalar);
+ assert_isa('File::Stat::Moose', $scalar);
+ assert_not_equals(0, $scalar->size);
my @array1 = stat($file);
assert_not_null(@array1);
@@ -82,10 +79,8 @@
};
sub test_lstat {
- my $self = shift;
-
my $scalar = lstat($file);
- assert_not_null($scalar);
+ assert_isa('File::Stat::Moose', $scalar);
my @array1 = lstat($file);
assert_not_null(@array1);
@@ -105,15 +100,13 @@
assert_raises( ['Exception::IO'], sub {
lstat($notexistant);
} );
-}
+};
sub test_lstat_symlink {
return unless $symlink;
- my $self = shift;
-
my $scalar = lstat($symlink);
- assert_not_null($scalar);
+ assert_isa('File::Stat::Moose', $scalar);
my @array1 = lstat($symlink);
assert_not_null(@array1);
@@ -134,6 +127,6 @@
assert_not_null(@array4);
assert_equals(13, scalar @array4);
assert_not_equals($array1[1], $array4[1]);
-}
+};
1;
Modified: File-Stat-Moose/trunk/t/tlib/File/Stat/MooseTest.pm
===================================================================
--- File-Stat-Moose/trunk/t/tlib/File/Stat/MooseTest.pm 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/t/tlib/File/Stat/MooseTest.pm 2008-12-29 22:04:45 UTC (rev 7193)
@@ -3,15 +3,16 @@
use strict;
use warnings;
-use base 'Test::Unit::TestCase';
+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 ();
+use File::Temp;
our ($file, $symlink, $notexistant);
@@ -31,214 +32,223 @@
};
sub test_new {
- my $self = shift;
my $obj = File::Stat::Moose->new;
- assert_not_null($obj);
- assert_true($obj->isa("File::Stat::Moose"), '$obj->isa("File::Stat::Moose")');
+ assert_isa('File::Stat::Moose', $obj);
assert_null($obj->size);
};
sub test_new_file {
- my $self = shift;
- my $obj = File::Stat::Moose->new(file => $file);
- assert_not_null($obj);
- assert_true($obj->isa("File::Stat::Moose"), '$obj->isa("File::Stat::Moose")');
+ my $obj = File::Stat::Moose->new( file => $file );
+ assert_isa('File::Stat::Moose', $obj);
assert_not_equals(0, $obj->size);
};
sub test_new_symlink {
return unless $symlink;
- my $self = shift;
my $obj1 = File::Stat::Moose->new(file => $symlink);
- assert_not_null($obj1);
- assert_true($obj1->isa("File::Stat::Moose"), '$obj1->isa("File::Stat::Moose")');
+ assert_isa('File::Stat::Moose', $obj1);
assert_not_equals(0, $obj1->size);
my $obj2 = File::Stat::Moose->new(file => $symlink, follow => 1);
- assert_not_null($obj2);
- assert_true($obj2->isa("File::Stat::Moose"), '$obj2->isa("File::Stat::Moose")');
+ assert_isa('File::Stat::Moose', $obj2);
assert_not_equals(0, $obj2->size);
assert_not_equals($obj1->ino, $obj2->ino);
-}
+};
sub test_new_exception_constraint {
- my $self = shift;
assert_raises( qr/does not pass the type constraint/, sub {
- my $obj = File::Stat::Moose->new(file => undef);
+ 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, 2, 3]);
+ my $obj = File::Stat::Moose->new( file => [1, 2, 3] );
} );
assert_raises( qr/does not pass the type constraint/, sub {
- my $obj = File::Stat::Moose->new(file => (bless {} => 'My::Class'));
+ 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);
+ my $obj = File::Stat::Moose->new( file => $file, follow => \1 );
} );
-}
+};
sub test_new_exception_io {
- my $self = shift;
assert_raises( ['Exception::IO'], sub {
- my $obj = File::Stat::Moose->new(file => $notexistant);
+ my $obj = File::Stat::Moose->new( file => $notexistant );
} );
};
sub test__deref_array {
- my $self = shift;
- my $obj = File::Stat::Moose->new(file => $file);
- assert_not_null($obj);
- assert_true($obj->isa("File::Stat::Moose"), '$obj->isa("File::Stat::Moose")');
+ my $obj = File::Stat::Moose->new( file => $file );
+ assert_isa('File::Stat::Moose', $obj);
assert_equals(13, scalar @$obj);
{
- foreach my $value (@$obj) {
- assert_matches(qr/^\d+$/, $value);
+ 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 $self = shift;
my $obj = File::Stat::Moose->new;
- assert_not_null($obj);
- assert_true($obj->isa("File::Stat::Moose"), '$obj->isa("File::Stat::Moose")');
+ assert_isa('File::Stat::Moose', $obj);
{
foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
- assert_null($obj->$attr);
+ assert_null($obj->$attr, $attr);
};
};
{
foreach my $attr (qw { atime mtime ctime }) {
- assert_raises( qr/is not one of the allowed types/, sub { $obj->$attr } );
+ assert_raises( qr/does not pass the type constraint/, sub {
+ $obj->$attr;
+ }, $attr );
};
};
$obj->file($file);
assert_equals($file, $obj->file);
- $obj->follow(1);
- assert_equals(1, $obj->follow);
- assert_not_null($obj->stat);
+ $obj->follow(TRUE);
+ assert_true($obj->follow);
+
+ $obj->sloppy(FALSE);
+ assert_false($obj->sloppy);
+
+ $obj->stat;
{
foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
- assert_matches(qr/^\d+$/, $obj->$attr);
+ 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_stat_sloppy {
+ my $obj = File::Stat::Moose->new;
+ assert_isa('File::Stat::Moose', $obj);
+
+ $obj->file($file);
+ $obj->follow(TRUE);
+
+ $obj->sloppy(TRUE);
+ assert_true($obj->sloppy);
+
+ $obj->stat;
{
+ 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_equals('DateTime', ref $obj->$attr);
+ assert_isa('DateTime', $obj->$attr, $attr) if defined $obj->$attr;
};
};
+ assert_not_equals(0, $obj->size);
};
sub test_stat_failure {
- my $self = shift;
my $obj = File::Stat::Moose->new;
- assert_not_null($obj);
+ assert_isa('File::Stat::Moose', $obj);
$obj->file($notexistant);
- $obj->follow(1);
+ $obj->follow(TRUE);
- assert_raises( ['Exception::IO'], sub { $obj->stat } );
+ assert_raises( ['Exception::IO'], sub {
+ $obj->stat;
+ } );
- assert_raises( ['Exception::Argument'], sub { $obj->stat('badargument') } );
+ assert_raises( ['Exception::Argument'], sub {
+ $obj->stat('badargument')
+ } );
};
sub test_lstat {
- my $self = shift;
my $obj = File::Stat::Moose->new;
- assert_not_null($obj);
- assert_true($obj->isa("File::Stat::Moose"), '$obj->isa("File::Stat::Moose")');
+ assert_isa('File::Stat::Moose', $obj);
{
foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
- assert_null($obj->$attr);
+ assert_null($obj->$attr, $attr);
};
};
{
foreach my $attr (qw { atime mtime ctime }) {
- assert_raises( qr/is not one of the allowed types/, sub { $obj->$attr } );
+ assert_raises( qr/does not pass the type constraint/, sub {
+ $obj->$attr
+ }, $attr );
};
};
$obj->file($file);
assert_equals($file, $obj->file);
- $obj->follow(0);
- assert_equals(0, $obj->follow);
- assert_not_null($obj->lstat);
+ $obj->follow(FALSE);
+ assert_false($obj->follow);
+
+ $obj->sloppy(FALSE);
+ assert_false($obj->sloppy);
+
+ $obj->lstat;
{
foreach my $attr (qw{ dev ino mode nlink uid gid rdev size blksize blocks }) {
- assert_matches(qr/^\d+$/, $obj->$attr);
+ assert_matches(qr/^\d+$/, $obj->$attr, $attr) if defined $obj->$attr;
};
};
assert_not_equals(0, $obj->size);
{
foreach my $attr (qw { atime mtime ctime }) {
- assert_equals('DateTime', ref $obj->$attr);
+ assert_isa('DateTime', $obj->$attr, $attr) if defined $obj->$attr;
};
};
};
-sub test_lstat_failure {
- my $self = shift;
+sub test_lstat_sloppy {
my $obj = File::Stat::Moose->new;
- assert_not_null($obj);
+ assert_isa('File::Stat::Moose', $obj);
- $obj->file($notexistant);
- $obj->follow(0);
+ $obj->file($file);
+ $obj->follow(FALSE);
- assert_raises( ['Exception::IO'], sub { $obj->lstat } );
+ $obj->sloppy(TRUE);
+ assert_true($obj->sloppy);
- assert_raises( ['Exception::Argument'], sub { $obj->lstat('badargument') } );
-};
-
-sub test_stat_static_method {
- my $self = shift;
- my $obj = File::Stat::Moose->stat($file);
- assert_not_null($obj);
- assert_true($obj->isa("File::Stat::Moose"), '$obj->isa("File::Stat::Moose")');
+ $obj->lstat;
+ {
+ 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_stat_static_method_failure {
- my $self = shift;
- assert_raises( ['Exception::IO'], sub {
- File::Stat::Moose->stat($notexistant);
- } );
- assert_raises( ['Exception::Argument'], sub {
- File::Stat::Moose->stat();
- } );
- assert_raises( ['Exception::Argument'], sub {
- File::Stat::Moose->stat($file, 'badargument');
- } );
-};
+sub test_lstat_failure {
+ my $obj = File::Stat::Moose->new;
+ assert_isa('File::Stat::Moose', $obj);
-sub test_lstat_static_method {
- my $self = shift;
- my $obj = File::Stat::Moose->lstat($file);
- assert_not_null($obj);
- assert_true($obj->isa("File::Stat::Moose"), '$obj->isa("File::Stat::Moose")');
- assert_not_equals(0, $obj->size);
-}
+ $obj->file($notexistant);
+ $obj->follow(FALSE);
-sub test_lstat_static_method_failure {
- my $self = shift;
assert_raises( ['Exception::IO'], sub {
- File::Stat::Moose->lstat($notexistant);
+ $obj->lstat;
} );
+
assert_raises( ['Exception::Argument'], sub {
- File::Stat::Moose->lstat();
+ $obj->lstat('badargument');
} );
- assert_raises( ['Exception::Argument'], sub {
- File::Stat::Moose->lstat($file, 'badargument');
- } );
};
1;
Copied: File-Stat-Moose/trunk/xt/benchmark.pl (from rev 7088, File-Stat-Moose/trunk/t/benchmark.pl)
===================================================================
--- File-Stat-Moose/trunk/xt/benchmark.pl (rev 0)
+++ File-Stat-Moose/trunk/xt/benchmark.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -0,0 +1,51 @@
+#!/usr/bin/perl -al
+
+use lib 'lib', '../lib';
+
+package My::CoreStat;
+our $n = 0;
+sub test {
+ my $size = (stat '/etc/passwd')[7];
+ $n++;
+}
+
+
+package My::FileStat;
+use File::stat;
+our $n = 0;
+sub test {
+ my $st = stat '/etc/passwd';
+ my $size = $st->size;
+ $n++;
+}
+
+
+package My::FileStatMoose;
+use File::Stat::Moose;
+our $n = 0;
+sub test {
+ my $size = File::Stat::Moose->new(file=>'/etc/passwd')->size;
+ $n++;
+}
+
+
+package My::FileStatMooseFunc;
+use File::Stat::Moose 'stat';
+our $n = 0;
+sub test {
+ my $size = (stat '/etc/passwd')[7];
+ $n++;
+}
+
+package main;
+
+use Benchmark ':all';
+
+my $result = timethese($ARGV[0] || -1, {
+ '1_CoreStat' => sub { My::CoreStat::test; },
+ '2_FileStat' => sub { My::FileStat::test; },
+ '3_FileStatMoose' => sub { My::FileStatMoose::test; },
+ '4_FileStatMooseFunc' => sub { My::FileStatMooseFunc::test; },
+});
+
+cmpthese($result);
Copied: File-Stat-Moose/trunk/xt/cover.sh (from rev 7088, File-Stat-Moose/trunk/t/cover.sh)
===================================================================
--- File-Stat-Moose/trunk/xt/cover.sh (rev 0)
+++ File-Stat-Moose/trunk/xt/cover.sh 2008-12-29 22:04:45 UTC (rev 7193)
@@ -0,0 +1,6 @@
+cd $(dirname $0)
+cd ..
+perl Build.PL
+cover -delete
+HARNESS_PERL_SWITCHES=-MDevel::Cover ./Build test
+cover
Deleted: File-Stat-Moose/trunk/xt/pod.t
===================================================================
--- File-Stat-Moose/trunk/xt/pod.t 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/xt/pod.t 2008-12-29 22:04:45 UTC (rev 7193)
@@ -1,11 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use Test::More;
-
-eval "use Test::Pod 1.14";
-plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
-
-all_pod_files_ok();
Modified: File-Stat-Moose/trunk/xt/pod_coverage.t
===================================================================
--- File-Stat-Moose/trunk/xt/pod_coverage.t 2008-12-29 17:57:58 UTC (rev 7192)
+++ File-Stat-Moose/trunk/xt/pod_coverage.t 2008-12-29 22:04:45 UTC (rev 7193)
@@ -5,11 +5,9 @@
use Test::More;
-use lib 't/tlib', 'tlib';
-
eval "use Test::Pod::Coverage 1.04";
plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
all_pod_coverage_ok({
- also_private => [ qr/^(BUILD|meta|unimport)$/ ],
+ also_private => [ qr/^(unimport|BUILD)$/ ],
});
Copied: File-Stat-Moose/trunk/xt/pod_syntax.t (from rev 7088, File-Stat-Moose/trunk/xt/pod.t)
===================================================================
--- File-Stat-Moose/trunk/xt/pod_syntax.t (rev 0)
+++ File-Stat-Moose/trunk/xt/pod_syntax.t 2008-12-29 22:04:45 UTC (rev 7193)
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+
+all_pod_files_ok();
Copied: File-Stat-Moose/trunk/xt/profile.pl (from rev 7088, File-Stat-Moose/trunk/t/profile.pl)
===================================================================
--- File-Stat-Moose/trunk/xt/profile.pl (rev 0)
+++ File-Stat-Moose/trunk/xt/profile.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -0,0 +1,11 @@
+#!/usr/bin/perl -d:DProf
+
+use lib 'lib', '../lib';
+
+use File::Stat::Moose;
+
+foreach (1..10000) {
+ my $size = File::Stat::Moose->new(file=>'/etc/passwd')->size;
+};
+
+print "tmon.out data collected. Call dprofpp\n";
Added: File-Stat-Moose/trunk/xt/trace.pl
===================================================================
--- File-Stat-Moose/trunk/xt/trace.pl (rev 0)
+++ File-Stat-Moose/trunk/xt/trace.pl 2008-12-29 22:04:45 UTC (rev 7193)
@@ -0,0 +1,9 @@
+#!/usr/bin/perl -d:Trace
+
+use lib 'lib', '../lib';
+
+use File::Stat::Moose;
+
+foreach (1..10) {
+ my $size = File::Stat::Moose->new(file=>'/etc/passwd')->size;
+};
More information about the Moose-commits
mailing list