develooper Front page | perl.perl5.porters | Postings from August 2014

[perl #121829] ExtUtils::Installed or ExtUtils::Packlist: add function for direct access of a distribution's packlist

Thread Next
From:
slaven@rezic.de via RT
Date:
August 23, 2014 05:46
Subject:
[perl #121829] ExtUtils::Installed or ExtUtils::Packlist: add function for direct access of a distribution's packlist
Message ID:
rt-4.0.18-29536-1408772807-358.121829-15-0@perl.org
Dana Pet 22. Kol 2014, 17:56:37, jkeenan reče:
> On Thu May 08 13:06:37 2014, slaven@rezic.de wrote:
> > It would be nice if either ExtUtils::Installed or ExtUtils::Packlist
> >  had a function for direct access of a packlist.
> 
> Slaven, Leon,
> 
> Can you be a bit more specific about what you mean by "direct access
> of a packlist"?
> 
> What would that function or method do?  Are you referring to a
> .packlist file or to something like this:
> 
> #####
> 'Test::Script' => {
>   'packlist' => bless( {
>     '/home/jkeenan/perl5/man/man3/Test::Script.3' => undef,
>     '/home/jkeenan/perl5/lib/perl5/Test/Script.pm' => undef
>   }, 'ExtUtils::Packlist' ),
>   'version' => '1.07',
>   'packlist_valid' => 1,
>   'packlist_file' => '/home/jkeenan/perl5/lib/perl5/x86_64-
> linux/auto/Test/Script/.packlist',
>   'modfile' => 'Test/Script.pm',
>   'version_from' => '/home/jkeenan/perl5/lib/perl5/Test/Script.pm',
>   'module' => 'Test::Script'
> },
> #####
> 
> Thank you very much.
> Jim Keenan

Currently there are the following methods to get the packlist of a module:

    use ExtUtils::Installed; $packlist = ExtUtils::Installed->new->packlist($module);

    use ExtUtils::Installed; $packlist = ExtUtils::Installed->packlist($module);

    use ExtUtils::Packlist; $packlist = ExtUtils::Packlist->new->packlist("/I/know/where/the/packlist/of/$module/is/located");

The first two may be slow and resource hungry. The third is fast, but one needs the knowledge where the packlist may be found.

I would suggest to add a new method find_packlist which could be used like this:

    $packlist_path = ExtUtils::Installed->find_packlist($module);
    $packlist = ExtUtils::Packlist->new($packlist_path);

find_packlist could look like this (pseudo code):

    sub find_packlist {
        my(undef, $module) = @_;
        (my $path = $module) =~ s{::}{/}g;
	$path .= "/.packlist";
        for my $incdir (@INC) {
	    my $trypath = "$incdir/auto/$path";
            return $trypath if -e $trypath;
        }
    }

Once find_packlist is there it could be used to re-implement the class method variant of ExtUtils::Installed::packlist, so ExtUtils::Installed->packlist won't construct the "default object" anymore, but fetch the packlist directly. As pseudo code:

    sub packlist {
        my ($self, $module) = @_;
        if (!ref $self) {
            my $packlist_path = $self->find_packlist($module);
            Carp::croak("$module is not installed") if (!$packlist);
            return ExtUtils::Packlist->new($packlist_path);
        } else {
            Carp::croak("$module is not installed") if (! exists($self->{$module}));
            return($self->{$module}{packlist});
        }
    }

If needed, there could also be more efficient versions for the validate() and version() methods in ExtUtils::Installed, too. The first one could also use find_packlist(), the second would use part of the logic of _make_entry().



---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=121829

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About