Comparer-file_num_links

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


     my $cmp = Comparer::file_num_links::gen_comparer();
     my @sorted = sort { $cmp->($a,$b) } "foo", "bar", "baz";

DESCRIPTION
    This comparer assumes the entries are filenames and will compare their
    number of (hard) links.

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_num_links>.

SOURCE
    Source repository is at

lib/Comparer/file_num_links.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[3] <=> $st2[3]
        ) * ($reverse ? -1 : 1)
    };
}

1;
# ABSTRACT: Compare file's number of (hard) links

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


This comparer assumes the entries are filenames and will compare their
number of (hard) links.

=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_num_links>.

=head1 SOURCE



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