AnnoCPAN

 view release on metacpan or  search on metacpan

lib/AnnoCPAN/Dist.pm  view on Meta::CPAN

    qr(/TODO$)i,
    qr(/AUTHORS?$)i,
);

# default files to include
my @include = (
    qr{.(pm|pod|pl)$}i,
    qr{/[^./]+$},       # files with no extension (typically scripts)
);

=item $class->new($fname, %options)

Create a new distribution object from a filename. Returns undef on failure.
Currently the only option is 'verbose'; if true, various diagnostic messages
are printed to STDOUT and STDERR when extracting the file.

=cut

sub new {
    my ($class, $fname, %options) = @_;
    
    return unless $fname =~ m{(authors/id/.*)};
    my $rel_pathname = $1;
    # let CPAN::DistnameInfo do the guessing
    my $self = $class->SUPER::new($fname);
    $self->{verbose}        = $options{verbose};
    $self->{rel_pathname}   = $rel_pathname;

    # XXX should make sure we like the filename...

    $self;
}

=item $obj->archive

Return the AnnoCPAN::Archive object for this distribution.

=cut

sub archive { 
    my ($self) = @_;
    $self->{archive} ||= AnnoCPAN::Archive->new($self->pathname);
}

=item $obj->mtime

Returns the modification time of the package (seconds since epoch).

=cut

sub mtime { shift->stat->mtime }

=item $obj->stat

Returns a L<File::stat> object for the distribution package.

=cut

sub stat {
    my ($self) = @_;
    $self->{stat} ||= File::stat::stat($self->pathname);
}

sub dbi_dist    { shift->{dbi_dist} }
sub dbi_distver { shift->{dbi_distver} }

=item $obj->files

Returns a list of all the filenames in the package.

=cut

sub files       { shift->archive->files }

=item $obj->read_file($fname)

Returns the contents of a file in the package.

=cut

sub read_file   { shift->archive->read_file(@_) }

=item $obj->verbose

Returns true if the verbose option was given when constructing the object.

=cut

sub verbose     { shift->{verbose} }

=item $obj->rel_pathname

Returns the pathname relative to the CPAN root (e.g.,
authors/id/A/AA/AAA/aaa-1.0.tar.gz)

=cut

sub rel_pathname{ shift->{rel_pathname} }

=item $obj->has_lib

Return true if the distribution has a lib/ directory.

=cut

sub has_lib {
    my ($self) = @_;
    defined $self->{has_lib} and return $self->{has_lib};
    $self->{has_lib} = (first { m|^(?:\./)?[^/]+/lib/| } $self->files) ? 1 : 0;
}

=item $obj->namespace_from_path($fname)

Given the path of one of the files in the archive, use heuristics to find out
its path in the perl module hierarchy. For example, given
"Dist-0.01/lib/My/Module.pm", returns "My/Module.pm".

=cut

sub namespace_from_path {
    my ($dist, $name) = @_;



( run in 1.679 second using v1.01-cache-2.11-cpan-4ac696b4eb4 )