Data-CTable
view release on metacpan or search on metacpan
CTable/Listing.pm view on Meta::CPAN
Options may appear in any order, before, after, or intermixed with the
path arguments. See below for options.
In addition to the Path field which contains the absolute or relative
path name of each listed item, _SCR_ also derives a number of
additional fields which you may include in the listing.
Available fields are:
Main path field:
Path Absolute or relative path of specified item
Fields from stat($Path) (see --fields, --all, or --info):
Device 0 dev device number of filesystem
INode 1 ino inode number
Mode 2 mode file mode (type and permissions)
NLink 3 nlink number of (hard) links to the file
UID 4 uid numeric user ID of file's owner
GID 5 gid numeric group ID of file's owner
RDev 6 rdev the device identifier (special files only)
Size 7 size total size of file, in bytes
ATime 8 atime last access time in seconds since the epoch
MTime 9 mtime last modify time in seconds since the epoch
CTime 10 ctime inode change time (NOT creation time)
BlkSize 11 blksize preferred block size for file system I/O
Blocks 12 blocks actual number of blocks allocated
Fields from localtime($MTime) (see --fields, --all, or --localtime):
(see man ctime or struct tm):
Sec 0 tm_sec The number of seconds after the minute, normally in
the range 0 to 59, but can be up to 61 to allow for
leap seconds.
Min 1 tm_min The number of minutes after the hour, in the range 0 to 59.
Hour 2 tm_hour The number of hours past midnight, in the range 0 to 23.
Day 3 tm_mday The day of the month, in the range 1 to 31.
TMon 4 tm_mon The number of months since January, in the range 0 to 11.
TYear 5 tm_year The number of years since 1900 (range 69 to 138)
WDay 6 tm_wday The number of days since Sunday, in the range 0 to 6.
YDay 7 tm_yday The number of days since January 1, in the range 0 to 365.
IsDST 8 tm_isdst A flag that indicates whether daylight saving
time is in effect at the time described. The
value is positive if daylight saving time is in
effect, zero if it is not, and negative if the
information is not available.
Fields from File::Basename (see --fields, --all, or --base):
Dir Directory component of Path
Base Base component of file name (without the Ext)
Ext Extension (any non-. characters after last . plus the . itself)
Other derived fields (see --fields, --all, or --derived):
File Filename component of Path (= Base + Ext)
Type File or directory
Perms Permissions (from Mode), specified as an octal string
Owner Unix owner name: getpwuid(UID) (empty on Win)
Group Unix owner name: getgrgid(GID) (empty on Win)
Mon TMon + 1 (range 1 to 12)
Year TYear + 1900 (range 1900 to 2038)
RTime ModTime as human-readable string (localtime(MTIME)."")
Stamp String-sortable semi-numeric time stamp (based on MTIME)
Field names are always built and output using mixed-case as indicated.
However, case is ignored by the --fields or --sort options (you may
specify the field names in all lower-case, for example). You may also
specify any shorter form of any field name as long as it is not
ambiguous. (For example "fi" for File or "pa" for Path.)
Available command-line options are:
Miscellaneous
-------------
Ignore all other options and print this help message instead.
--help
-h
Don't turn off progress() calls in the table.
--verbose
-v
Controlling files (rows) included in listing
--------------------------------------------
Don't include children of specified directories.
--nochildren
--nochild
--noc
Don't list specified directories themselves (but do list their
children unless --noc).
--notop
--not
Recursively include all sub-directories in listings (overrides
--nochildren).
--recurse
-r
Restrict listing to only directories (d) or files (f).
--type=d
-ty=d
--type=f
-ty=f
CTable/Listing.pm view on Meta::CPAN
my $TInfo = [localtime($Times->[$FNum])];
foreach my $n ('00'..'08')
{
## First time through (and only time through if no records
## present), just make the columns.
$t->col("T$n"), next if $FNum == -1;
## Fill stat values into pre-sized vectors in the table.
$t->col("T$n")->[$FNum] = $TInfo->[$n];
}
}
## Change some field names.
$t->col_rename(qw( T00 Sec
T01 Min
T02 Hour
T03 Day
T04 TMon
T05 TYear
T06 WDay
T07 YDay
T08 IsDST
));
## Build the "basename" fields...
foreach my $FNum (-1..$#$Paths)
{
## Get stats for the file...
use File::Basename qw(fileparse);
my $FInfo = [(fileparse($Paths->[$FNum], '\.[^\.]+'))[1,0,2]]
unless $FNum == -1;
foreach my $n ('00'..'02')
{
## First time through (and only time through if no records
## present), just make the columns.
$t->col("F$n"), next if $FNum == -1;
## Fill stat values into pre-sized vectors in the table.
$t->col("F$n")->[$FNum] = $FInfo->[$n];
}
}
## Change some field names.
$t->col_rename(qw( F00 Dir
F01 Base
F02 Ext
));
## Add a column showing the full file name.
$t->col(File => $t->calc(sub{"$main::Base$main::Ext"}));
$t->col(Type => $t->calc(sub{-d $main::Path ? "D" : "F"}));
## Add a Perms field showing permission component of (stat)[2]
## formatted as a 4-digit octal number.
$t->col(Perms => [map {sprintf("%04o", $_ & 0777)} @{$t->col('Mode')}]);
## Add columns translating the UID and GID into their string form.
$t->col(Owner => [map {((eval{getpwuid($_)})[0]) } @{$t->col('UID' )}]);
$t->col(Group => [map {((eval{getgrgid($_)})[0]) } @{$t->col('GID' )}]);
## Add a column showing the full file name.
$t->col(Mon => $t->calc(sub{$main::TMon + 1}));
$t->col(Year => $t->calc(sub{$main::TYear + 1900}));
## Add some time stamps -- one human-readable and one computer-sortable.
$t->col(RTime => $t->calc(sub{localtime($main::MTime).""}));
use POSIX;
$t->col(Stamp => $t->calc(sub{strftime("%Y%m%d%H%M%S", localtime($main::MTime))}));
return($t);
}
=pod
$Class->process_path_args()
Generates the file listing by interpreting the file-related
command-line options.
=cut
{};
sub process_path_args
{
my $Class = shift;
my ($Opts) = @_;
## Get the paths option.
my $Paths = $Opts->{args};
## Get details about paths on the current platform
my ($Sep, $Up, $Cur) = @{path_info()}{qw(sep up cur)};
## Default file list is the current directory.
$Paths = [$Cur] unless (ref($Paths) eq 'ARRAY') && @$Paths;
## Glob the paths to support shell-like wildcards on all
## platforms or when calling from a script.
$Paths = [map {my $x=[glob $_]; @$x ? @$x : $_} @$Paths];
## Validate / canonicalize path arguments.
$Paths = [map
{
## Ensure trailing $Sep on dir names
($_) =~ s{([^\Q$Sep\E])$ }{$1$Sep}ox if -d;
## Filter/warn re: existence of items we're going to list
(-e $_ ?
$_ :
do{$Class->warn("No such file or directory '$_'"); ()});
} @$Paths];
my $Recurse = $Opts->{recurse};
my $NoTop = $Opts->{notop};
my $NoChildren = $Opts->{nochildren} && !$Recurse;
my $Type = $Opts->{type};
( run in 2.661 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )