PerlPowerTools

 view release on metacpan or  search on metacpan

bin/ls  view on Meta::CPAN

				my $path = File::Spec->canonpath(File::Spec->catdir($dir_name,$entry));
				my @dirs = $class->DirEntries($Options, $path);
				$class->List($path, $Options, 1, 0, @dirs);
				}
			}
		}
	}

# ------ sort file list based on %Options
sub Order {
	my( $class, $Options, $A, @Entries ) = @_;

	# ------ sort by size, largest first
	if( exists $Options->{'S'} ) {
		if( exists $Options->{'r'} ) {
			@Entries = sort { $A->{$a}->size <=> $A->{$b}->size } @Entries;
			}
		else {
			@Entries = sort { $A->{$b}->size <=> $A->{$a}->size } @Entries;
			}
		}
	# ------ sort by time, most recent first
	elsif( grep { exists $Options->{$_} } qw(t c u) ) {
		if( exists $Options->{'r'} ) {
			if( exists $Options->{'u'} ) {
				@Entries = sort { $A->{$a}->atime <=> $A->{$b}->atime } @Entries;
				}
			elsif( exists $Options->{'c'} ) {
				@Entries = sort { $A->{$a}->ctime <=> $A->{$b}->ctime } @Entries;
				}
			else {
				@Entries = sort { $A->{$a}->mtime <=> $A->{$b}->mtime } @Entries;
				}
			}
		else {
			if( exists $Options->{'u'} ) {
				@Entries = sort { $A->{$b}->atime <=> $A->{$a}->atime } @Entries;
				}
			elsif( exists $Options->{'c'} ) {
				@Entries = sort { $A->{$b}->ctime <=> $A->{$a}->ctime } @Entries;
				}
			else {
				@Entries = sort { $A->{$b}->mtime <=> $A->{$a}->mtime } @Entries;
				}
			}
	# ------ sort by name
		}
	elsif( ! exists $Options->{'f'} ) {
		if( exists $Options->{'r'} ) {
			@Entries = sort { $b cmp $a } @Entries;
			}
		else {
			@Entries = sort { $a cmp $b } @Entries;
			}
		}

	return @Entries;
	}

sub Getgrgid { getgrgid($_[1]) }
sub Getpwuid { getpwuid($_[1]) }

BEGIN {
	my $NO_GETGRGID = ! eval { my $dummy = ""; $dummy = (getpwuid(0))[0] };

	if( $NO_GETGRGID ) {
		no warnings qw(redefine);
		no strict qw(refs);
		*{'Getgrgid'} = sub { ($_[1], 0) };
		*{'Getpwuid'} = sub { ($_[1], 0) };
		}
	}

sub my_exit {
	my( $class, $code ) = @_;
	CORE::exit $code;
	}

sub warn_fh { \*STDERR }
sub my_warn {
	my( $class, $message, $prepend ) = @_;
	$prepend = 1 unless defined $prepend;
	$message = PROGRAM . ": " . $message if $prepend;
	print { $class->warn_fh } $message;
	}

sub output_fh { \*STDOUT }
sub output {
	my( $class, @messages ) = @_;
	print { $class->output_fh } @messages;
	}

sub _opts_string {
	#  macOS only                          *                  *
	#                  1ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy%
	my $opts_string = '1A CF   L  RST Wa cd fg iklmnopqrstu wx';
	$opts_string =~ s/\s+//g;
	$opts_string;
	}

sub process_options {
	require Getopt::Std;

	my( $class, @args ) = @_;

	my $Options = {};

	my $Supported = $class->_supported_options;

	my %original_positions;
	foreach my $i ( 0 .. $#args ) {
		my $arg = $args[$i];
		last unless $arg =~ /\A-/;
		last if $arg eq '--';
		( my $letter = $arg ) =~ s/\A--?//;
		$original_positions{$letter} = $i;
		}

	return $class->VERSION_MESSAGE if exists $original_positions{'version'};
	return $class->usage(
		-verbose => 2,
		-output  => $class->error_fh,
		) if exists $original_positions{'help'};

bin/ls  view on Meta::CPAN

invoked without file/directory name arguments, it lists the contents
of the current directory. Otherwise, B<ls> lists information about the
files and information about the contents of the directories (but see
B<-d>).  Furthermore, without any option arguments B<ls> just lists
the names of files and directories. All files are listed before all
directories. The default sort order is ascending ASCII on filename.

=head2 OPTIONS

The BSD options C<1ACFLRSTWacdfgiklmnopqrstux> are recognized, but
only C<1RSacdfiklnrstu> are implemented:

=over 4

=item -1

List entries 1 per line (default if output is not a tty). This is
disabled by any of C<-C>, C<-x>, or C<-l>.

=item -R

Recursively list the contents of all directories, breadth-first.

=item -S

Sort descending by size. This is disabled by C<-t>.

=item -a

List all files (normally files starting with '.' are ignored).

=item -c

Sort by descending last modification time of inode. This is
disabled by any of C<-u> or C<-U>.

=item -d

Do not list directory contents.

=item -f

Do not sort -- list in whatever order files/directories are returned
by the directory read function. This option implies -a.

=item -i

List file inode number.  (Doesn't mean much on non-inode systems.)

=item -k

When used with B<-s>, list file/directory size in 1024-byte blocks.

=item -l

Long format listing of mode -- # of links, owner name, group name,
size in bytes, time of last modification, and name.

=item -n

List numeric uid and gid (default on platforms without getpwuid()).

=item -r

Reverse sorting order.

=item -s

List file/directory size in 512-byte blocks.  (May not mean much
on non-Unix systems.)

=item -t

Sort by descending last modification time.

=item -u

Sort by descending last access time.

=item -w

Set the column width for the output. The default is the window size,
or 80 if the program cannot determine the window size. A column
width of 0 means unlimited.

=back

=head1 ENVIRONMENT

The working of I<ls> is not influenced by any environment variables.

=head1 BUGS

The file metadata from C<stat> is used, which may not necessarily mean
much on non-Unix systems. Specifically, the uid, gid, inode, and
block numbers may be meaningless (or less than meaningful at least).

The C<-l> option does not yet list the major and minor device numbers
for special files, but it does list the value of the 'dev' field as 2
hex 16-bit words. Doing this properly would probably require
filesystem type probing.

=head1 AUTHOR

This Perl implementation of I<ls> was written by Mark Leighton Fisher
of Thomson Consumer Electronics, I<fisherm@tce.com>.

Portions of Stat::lsmode from Mark Jason Dominus have been inlined
into this program uder the perl license. See L<http://www.plover.com/~mjd/perl/lsMode/>.

=head1 COPYRIGHT and LICENSE

This program is free and open software. You may use, modify,
distribute, and sell this program (and any modified variants) in any
way you wish, provided you do not restrict others from doing the same.

=cut




( run in 0.435 second using v1.01-cache-2.11-cpan-39bf76dae61 )