Fedora-App-MaintainerTools

 view release on metacpan or  search on metacpan

lib/Fedora/App/MaintainerTools/SpecData/New.pm  view on Meta::CPAN

#
# given a cpanplus::module, try to extract its description from the
# embedded pod in the extracted files. this would be the first paragraph
# of the DESCRIPTION head1.
#
sub _build_description {
    my $self = shift @_;

    my $module = $self->module;

    # where tarball has been extracted
    my $path   = dirname $module->_status->extract;
    my $parser = Pod::POM->new;

    my @docfiles =
        map  { "$path/$_" }               # prepend extract directory
        sort { length $a <=> length $b }  # sort by length
        grep { /\.(pod|pm)$/ }            # filter potentially pod-containing
        @{ $module->_status->files };     # list of embedded files

    my $desc;

    # parse file, trying to find a header
    DOCFILE:
    foreach my $docfile ( @docfiles ) {

        # extract pod; the file may contain no pod, that's ok
        my $pom = $parser->parse_file($docfile);
        next DOCFILE unless defined $pom;

        HEAD1:
        foreach my $head1 ($pom->head1) {

            next HEAD1 unless $head1->title eq 'DESCRIPTION';

            my $pom  = $head1->content;
            my $text = $pom->present('Pod::POM::View::Text');

            # limit to 3 paragraphs at the moment
           my @paragraphs = (split /\n\n/, $text)[0..2];
            #$text = join "\n\n", @paragraphs;
            $text = q{};
            for my $para (@paragraphs) { $text .= $para || ''}

            # autoformat and return...
            return autoformat $text, { all => 1 };
        }
    }

    return '%{summary}.';
}

#############################################################################
# license

# this is largely stolen from CPANPLUS::Dist::RPM...  in need of some serious
# refactoring but works for now.

has license_map => (
    traits => [ 'MooseX::AttributeHelpers::Trait::Collection::Hash' ],
    is => 'ro', isa => 'HashRef[Str]', lazy_build => 1,
    provides => { get => 'license_shortname' },
);

has license_comment => (is => 'rw', isa => 'Maybe[Str]', lazy_build => 1);

sub _build_license_comment { undef }

sub _build_license_map {

    return {

        # classname                         => shortname
        'Software::License::AGPL_3'         => 'AGPLv3',
        'Software::License::Apache_1_1'     => 'ASL 1.1',
        'Software::License::Apache_2_0'     => 'ASL 2.0',
        'Software::License::Artistic_1_0'   => 'Artistic',
        'Software::License::Artistic_2_0'   => 'Artistic 2.0',
        'Software::License::BSD'            => 'BSD',
        'Software::License::FreeBSD'        => 'BSD',
        'Software::License::GFDL_1_2'       => 'GFDL',
        'Software::License::GPL_1'          => 'GPL',
        'Software::License::GPL_2'          => 'GPLv2',
        'Software::License::GPL_3'          => 'GPLv3',
        'Software::License::LGPL_2_1'       => 'LGPLv2',
        'Software::License::LGPL_3_0'       => 'LGPLv3',
        'Software::License::MIT'            => 'MIT',
        'Software::License::Mozilla_1_0'    => 'MPLv1.0',
        'Software::License::Mozilla_1_1'    => 'MPLv1.1',
        'Software::License::Perl_5'         => 'GPL+ or Artistic',
        'Software::License::QPL_1_0'        => 'QPL',
        'Software::License::Sun'            => 'SPL',
        'Software::License::Zlib'           => 'zlib',
    };
}

sub _build_license {
    my $self = shift @_;

    Class::MOP::load_class('File::Find::Rule');

    #my $module = $self->parent;
    my $module = $self->module;

    my $lic_comment = q{};

    # First, check what CPAN says
    my $cpan_lic = $module->details->{'Public License'};

    ### $cpan_lic

    # then, check META.yml (if existing)
    my $extract_dir = dir $module->extract;
    my $meta_file   = file $extract_dir, 'META.yml';
    my @meta_lics;

    if (-e "$meta_file" && -r _) {

        my $meta = $meta_file->slurp;
        @meta_lics =
            Software::LicenseUtils->guess_license_from_meta_yml($meta);



( run in 1.232 second using v1.01-cache-2.11-cpan-39bf76dae61 )