App-GitFind

 view release on metacpan or  search on metacpan

lib/App/GitFind/Actions.pm  view on Meta::CPAN


# writeable

# }}}2
# No-argument actions {{{2

# delete

sub do_ls {
    state $loaded = (require App::GitFind::FileStatLs, true);
    print App::GitFind::FileStatLs::ls_stat($_[1]->path);
    true
}
    # TODO optimization?  Pull the stat() results from $_[1] rather than
    # re-statting.  May not be an issue.

sub do_print {
    say $_[0]->dot_relative_path($_[1]);
    true
}

sub do_print0 { print $_[0]->dot_relative_path($_[1]), "\0"; true }

# prune

lib/App/GitFind/Entry.pm  view on Meta::CPAN


use 5.010;
use strict;
use warnings;
use App::GitFind::Base;

our $VERSION = '0.000002';

use parent 'App::GitFind::Class';

# Fields.  Not all have values.  The default stat() returns are provided
# for the convenience of subclasses --- override them in any subclass
# that does not provide _lstat.
use Class::Tiny qw(searchbase);

# Read-only lazy accessors
use Class::Tiny::Immutable {

    # The lstat() results for this entry.  lstat() rather than stat()
    # because searches treat links as individual entries rather than
    # as their referents.  (TODO global option?)
    # This is a lazy initializer so we don't stat() if we don't have to.
    _lstat => sub { ... },
        # Returns an arrayref of lstat() results.  Must be overriden in
        # subclasses unless the below uses of _lstat are overridden.

    dev => sub { $_[0]->_lstat->[0] },      # device number of filesystem
    ino => sub { $_[0]->_lstat->[1] },      # inode number
    mode => sub { $_[0]->_lstat->[2] },     # file mode  (type and permissions)
    nlink => sub { $_[0]->_lstat->[3] },    # number of (hard) links to the file
    uid => sub { $_[0]->_lstat->[4] },      # numeric user ID of file's owner
    gid => sub { $_[0]->_lstat->[5] },      # numeric group ID of file's owner
    rdev => sub { $_[0]->_lstat->[6] },     # the device identifier (special files only)
    size => sub { $_[0]->_lstat->[7] },     # total size of file, in bytes

lib/App/GitFind/Entry/GitIndex.pm  view on Meta::CPAN

# Fields.  Not all have values.
use Class::Tiny _qwc <<'EOT';
    obj     # A Git::Raw::Index::Entry instance.  Required.
    repo    # A Git::Raw::Repository instance.  Required.
EOT

use Class::Tiny::Immutable {
    # Lazy cache of an App::GitFind::PathClassMicro::File instance for this path
    '_pathclass' => sub { App::GitFind::PathClassMicro::File->new($_[0]->repo->workdir, $_[0]->obj->path) },

    '_lstat' => sub { [$_[0]->_pathclass->lstat()] },

    isdir => sub { false },     # Git doesn't store dirs, only files.
    name => sub { $_[0]->_pathclass->basename },
    path => sub { $_[0]->_pathclass->relative($_[0]->searchbase) },
};

# Docs {{{1

=head1 NAME

lib/App/GitFind/Entry/PathClass.pm  view on Meta::CPAN

use App::GitFind::PathClassMicro;

our $VERSION = '0.000002';

use parent 'App::GitFind::Entry';

# Fields.  Not all have values.
use Class::Tiny
    'obj';      # An App::GitFind::PathClassMicro::Entity instance.  Required.
use Class::Tiny::Immutable {
    '_lstat' => sub { [$_[0]->obj->lstat()] },

    isdir => sub { $_[0]->obj->is_dir },
    name => sub { $_[0]->obj->basename },
    path => sub { $_[0]->obj->relative($_[0]->searchbase) },

};

# Docs {{{1

=head1 NAME

lib/App/GitFind/FileStatLs.pm  view on Meta::CPAN

App::GitFind::FileStatLs - Provide stat information in ls -l format

=head1 SYNOPSIS

B<NOTICE:> This is a copy of L<File::Stat::Ls> with modifications, as found at
L<https://github.com/cxw42/File-Stat-Ls>.

  use App::GitFind::FileStatLs;

  my $obj = App::GitFind::FileStatLs->new;
  my $ls = $obj->ls_stat('/my/file/name.txt');
    # E.g., " -r-xr-xr-x 1 root other 4523 Jul 12 09:49 /my/file/name.txt"

=head1 MODIFICATIONS

In L</ls_stat ($fn)>:

=over

=item *

lib/App/GitFind/FileStatLs.pm  view on Meta::CPAN

Input variables:

  $fn - file name

Variables used or routines called:

  None

How to use:

   my $ls = ls_stat($fn);
   # NOT $self->ls_stat($fn) --- not supported

Return: the ls string such as one of the following:

  -r-xr-xr-x   1 root     other         4523 Jul 12 09:49 uniq
  drwxr-xr-x   2 root     other         2048 Jul 12 09:50 bin
  lrwxrwxrwx   1 oracle7  dba             40 Jun 12  2002 linked.pl -> /opt/bin/linked2.pl

The output B<includes> a trailing newline.

=cut

lib/App/GitFind/FileStatLs.pm  view on Meta::CPAN

    my $fmt = "%10s %3d %7s %4s %12d %12s %-s%s\n";
    return sprintf $fmt, $fm,$nlink,$ud,$gd,$size,$mt,$fn,$link_to;
}

=head2 stat_attr ($fn, $typ)

Input variables:

  $fn - file name for getting stat attributes
     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
      $atime,$mtime,$ctime,$blksize,$blocks) = stat($fn);
  $typ - what type of object that you want it to return.
    The default is to return a hash containing filename, longname,
    and a hash ref with all the element from stat.
    SFTP - to return a Net::SFTP::Attributes object

Variables used or routines called:

  ls_stat

How to use:

lib/App/GitFind/FileStatLs.pm  view on Meta::CPAN

    (require Carp, Carp::croak "ERR: no file name for stat_attr.\n") if ! $fn;
    return undef if ! $fn;
    my $vs  = 'dev,ino,mode,nlink,uid,gid,rdev,size,atime,mtime,';
       $vs .= 'ctime,blksize,blocks';
    my $v1  = 'flags,perm,uid,gid,size,atime,mtime';
    my $ls = ls_stat $fn;  chomp $ls;
    my @a = (); my @v = ();
    my $attr = {};
    if ($typ && $typ =~ /SFTP/i) {
        @v = split /,/, $v1;
        @a = (stat($fn))[1,2,4,5,7,8,9];
        %$attr = map { $v[$_] => $a[$_] } 0..$#a ;
        # 'SSH2_FILEXFER_ATTR_SIZE' => 0x01,
        # 'SSH2_FILEXFER_ATTR_UIDGID' => 0x02,
        # 'SSH2_FILEXFER_ATTR_PERMISSIONS' => 0x04,
        # 'SSH2_FILEXFER_ATTR_ACMODTIME' => 0x08,
        $attr->{flags} = 0;
        $attr->{flags} |= 0x01;
        $attr->{flags} |= 0x02;
        $attr->{flags} |= 0x04;
        $attr->{flags} |= 0x08;
        return wantarray ? %{$attr} : $attr;
    } else {
        @v = split /,/, $vs;
        @a = stat($fn);
        %$attr = map { $v[$_] => $a[$_] } 0..$#a ;
    }
    my %r = (filename=>$fn, longname=>$ls, a=>$attr);
    # foreach my $k (keys %r) { print "$k=$r{$k}\n"; }
    # foreach my $k (keys %a) { print "$k=$a{$k}\n"; }
    # print "X: " . (wantarray ? %r : \%r) . "\n";
    return wantarray ? %r : \%r;
}

1;

lib/App/GitFind/PathClassMicro.pm  view on Meta::CPAN

  my $self = shift;
  return $self if $self->is_absolute;
  return $self->new($self->_spec->rel2abs($self->stringify, @_));
}

sub relative {
  my $self = shift;
  return $self->new($self->_spec->abs2rel($self->stringify, @_));
}

sub stat  { [stat("$_[0]")] }
sub lstat { [lstat("$_[0]")] }

sub PRUNE { return \&PRUNE; }

1;
# End of App::GitFind::PathClassMicro::Entity

=head1 NAME

App::GitFind::PathClassMicro::Entity - Base class for files and directories

lib/App/GitFind/PathClassMicro.pm  view on Meta::CPAN


This method will remove the file in a way that works well on all
platforms, and returns a boolean value indicating whether or not the
file was successfully removed.

C<remove()> is better than simply calling Perl's C<unlink()> function,
because on some platforms (notably VMS) you actually may need to call
C<unlink()> several times before all versions of the file are gone -
the C<remove()> method handles this process for you.

=item $st = $file->stat()

Invokes C<< File::stat::stat() >> on this file and returns a
L<File::stat> object representing the result.

MODIFIED: returns an arrayref of C<stat()> results.

=item $st = $file->lstat()

Same as C<stat()>, but if C<$file> is a symbolic link, C<lstat()>
stats the link instead of the file the link points to.

MODIFIED: returns an arrayref of C<lstat()> results.

=item $class = $file->dir_class()

Returns the class which should be used to create directory objects.

Generally overridden whenever this class is subclassed.

=item $copy = $file->copy_to( $dest );

Copies the C<$file> to C<$dest>. It returns a L<App::GitFind::PathClassMicro::File>

lib/App/GitFind/PathClassMicro.pm  view on Meta::CPAN

At the time of this writing, all combinations of these two parameters
are supported I<except> C<< depthfirst => 0, preorder => 0 >>.

C<callback> is normally not required to return any value. If it
returns special constant C<App::GitFind::PathClassMicro::Entity::PRUNE()> (more easily
available as C<< $item->PRUNE >>),  no children of analyzed
item will be analyzed (mostly as if you set C<$File::Find::prune=1>). Of course
pruning is available only in C<preorder>, in postorder return value
has no effect.

=item $st = $file->stat()

Invokes C<< File::stat::stat() >> on this directory and returns a
C<File::stat> object representing the result.

MODIFIED: returns an arrayref of C<stat()> results.

=item $st = $file->lstat()

Same as C<stat()>, but if C<$file> is a symbolic link, C<lstat()>
stats the link instead of the directory the link points to.

MODIFIED: returns an arrayref of C<lstat()> results.

=item $class = $file->file_class()

Returns the class which should be used to create file objects.

Generally overridden whenever this class is subclassed.

=back

=head1 AUTHOR



( run in 1.536 second using v1.01-cache-2.11-cpan-49f99fa48dc )