Skip Menu |

This queue is for tickets about the File-Listing CPAN distribution.

Report information
The Basics
Id: 72081
Status: resolved
Priority: 0/
Queue: File-Listing

People
Owner: Nobody in particular
Requestors: SHAW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 6.03
Fixed in: (no value)



Subject: Lines With "." or ".." are ignored
Any reason to ignore listings with "." and ".." (maybe it's something that from its LWP days)? I think the module should just parse and not decide what the caller may or may not want. If there is a need for this maybe an option could be provided to disable this behavior or a note added to the docs. I ran into this while parsing single listings generated by `ls -ld PATH`. -Skye
Reason is that I don't care about those normally. Saves me work not to have to ignore them in the parse_dir() output. If this were to change it must be with some explicit param asking for it. It would also have the good effect of documenting this behavior. Patches welcome.
What do you think about the attached. If you like it I can add docs. Since parse_dir() accepts 4 positional arguments, a package variable seems like the best approach. The use of `our` would make things a little cleaner but...
Subject: ls-la.patch
diff -x'*.json' -x'*.yml' -urpN File-Listing-6.04/lib/File/Listing.pm File-Listing-6.04-patch1/lib/File/Listing.pm --- File-Listing-6.04/lib/File/Listing.pm 2012-02-15 17:01:41.000000000 -0500 +++ File-Listing-6.04-patch1/lib/File/Listing.pm 2014-06-28 00:18:09.000000000 -0400 @@ -7,6 +7,9 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(parse_dir); +# If true parse '.' and '..' +$ALL = 0; + use strict; use Carp (); @@ -32,7 +35,6 @@ sub parse_dir ($;$$$) sub line { Carp::croak("Not implemented yet"); } sub init { } # Dummy sub - sub file_mode ($) { Carp::croak("Input to file_mode() must be a 10 character string.") @@ -164,7 +166,7 @@ sub line /x ) { - return if $name eq '.' || $name eq '..'; + return if ($name eq '.' || $name eq '..') && !$File::Listing::ALL; $name = "$curdir/$name" if length $curdir; my $type = '?'; if ($kind =~ /^l/ && $name =~ /(.*) -> (.*)/ ) { @@ -258,7 +260,7 @@ sub line (.+)$ # File name /x ) { - return if $name eq '.' || $name eq '..'; + return if ($name eq '.' || $name eq '..') && !$File::Listing::ALL; $name = "$curdir/$name" if length $curdir; my $type = '?'; if ($size_or_dir eq '<DIR>') { diff -x'*.json' -x'*.yml' -urpN File-Listing-6.04/t/ls-la.t File-Listing-6.04-patch1/t/ls-la.t --- File-Listing-6.04/t/ls-la.t 1969-12-31 19:00:00.000000000 -0500 +++ File-Listing-6.04-patch1/t/ls-la.t 2014-06-28 00:29:17.000000000 -0400 @@ -0,0 +1,24 @@ +#!perl -w + +use Test; +plan tests => 5; + +use File::Listing; + +$File::Listing::ALL = 1; + +@dir = parse_dir(<<'EOT'); +total 0 +drwxr-xr-x 4 aas users 1024 Mar 16 15:47 . +drwxr-xr-x 11 aas users 1024 Mar 15 19:22 .. +drwxr-xr-x 2 aas users 1024 Mar 16 15:47 CVS +EOT + +ok(@dir, 3); + +ok($dir[0][0], "."); +ok($dir[0][1], "d"); + +ok($dir[1][0], ".."); +ok($dir[1][1], "d"); +
Hello, I am the new maintainer of this module. I'm okay adding a feature like this but I am not keen on using a global variable to control it. If you want to make a PR against the new canonical repository: https://github.com/PerlAlien/File-Listing I'd be happy to review it.
Migrating this ticket to Github: https://github.com/PerlAlien/File-Listing/issues/8