Comparer-file_mtime

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


     # find directories named '*.git' that are newer than 7 days, and sort them by newest first
     % find -maxdepth 1 -type d -name '*.git' -mtime -7 | sort-by-comparer file_mtime -r

DESCRIPTION
    This comparer assumes the entries are filenames and will compare their
    modification time.

COMPARER ARGUMENTS
  follow_symlink
    Bool, default true. If set to false, will use lstat() function instead
    of the default stat().

  reverse
    Bool.

HOMEPAGE
    Please visit the project's homepage at
    <https://metacpan.org/release/Comparer-file_mtime>.

SOURCE
    Source repository is at

lib/Comparer/file_mtime.pm  view on Meta::CPAN

    };
}

sub gen_comparer {
    my %args = @_;

    my $follow_symlink = $args{follow_symlink} // 1;
    my $reverse = $args{reverse};

    sub {
        my @st1 = $follow_symlink ? stat($_[0]) : lstat($_[0]);
        my @st2 = $follow_symlink ? stat($_[1]) : lstat($_[1]);

        (
            $st1[9] <=> $st2[9]
        ) * ($reverse ? -1 : 1)
    };
}

1;
# ABSTRACT: Compare file's mtime (modification time)

lib/Comparer/file_mtime.pm  view on Meta::CPAN


This comparer assumes the entries are filenames and will compare their
modification time.

=for Pod::Coverage ^(meta|gen_comparer)$

=head1 COMPARER ARGUMENTS

=head2 follow_symlink

Bool, default true. If set to false, will use C<lstat()> function instead of the
default C<stat()>.

=head2 reverse

Bool.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Comparer-file_mtime>.

=head1 SOURCE



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