| 1 | # | ||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of CPANPLUS-Dist-Mageia | ||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2011 by Jerome Quelin. | ||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | package CPANPLUS::Dist::Mageia; | ||||||||||||||||||||||||||||||||||||||
| 14 | # ABSTRACT: A CPANPLUS backend to build Mageia RPMs | ||||||||||||||||||||||||||||||||||||||
| 15 | 1 | $CPANPLUS::Dist::Mageia::VERSION = '2.103'; | |||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use base 'CPANPLUS::Dist::Base'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use CPANPLUS::Error; # imported subs: error(), msg() | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use File::Basename qw{ basename dirname }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use File::Copy qw{ copy }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use File::ShareDir qw{ dist_dir }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use File::Slurp qw{ slurp }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use IPC::Cmd qw{ run can_run }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use List::Util qw{ first }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use List::MoreUtils qw{ uniq }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Pod::POM; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Pod::POM::View::Text; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use Text::Wrap; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my @RPMSUBDIRS = qw{ build rpm source spec srcrpm }; | |||||||||||||||||||||||||||||||||||||
| 34 | 1 | my %RPMDIR = map {do { chomp(my $d=qx[ rpm --eval %_${_}dir ]); $_, $d; }} @RPMSUBDIRS ; | |||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | # -- class methods | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub format_available { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
format_available: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 40 | # check mageia release file | ||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( ! -f '/etc/mageia-release' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | error( 'not on a mageia system' ); | |||||||||||||||||||||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $flag; | |||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | # check rpm tree structure | ||||||||||||||||||||||||||||||||||||||
| 49 | 0 | foreach my $subdir ( keys %RPMDIR ) { | |||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $dir = "$RPMDIR{$subdir}"; | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | next if -d $dir; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | error( "missing directory '$dir'" ); | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | $flag++; | |||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | # check prereqs | ||||||||||||||||||||||||||||||||||||||
| 57 | 0 | for my $prog ( qw[ rpm rpmbuild gcc ] ) { | |||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | next if can_run($prog); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 59 | 0 | error( "'$prog' is a required program to build mageia packages" ); | |||||||||||||||||||||||||||||||||||||
| 60 | 0 | $flag++; | |||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return not $flag; | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | # -- public methods | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $status = $self->status; # an Object::Accessor | |||||||||||||||||||||||||||||||||||||
| 73 | # distname: Foo-Bar | ||||||||||||||||||||||||||||||||||||||
| 74 | # distvers: 1.23 | ||||||||||||||||||||||||||||||||||||||
| 75 | # extra_files: qw[ /bin/foo /usr/bin/bar ] | ||||||||||||||||||||||||||||||||||||||
| 76 | # rpmname: perl-Foo-Bar | ||||||||||||||||||||||||||||||||||||||
| 77 | # rpmpath: $RPMDIR/RPMS/noarch/perl-Foo-Bar-1.23-1mga2008.0.noarch.rpm | ||||||||||||||||||||||||||||||||||||||
| 78 | # rpmvers: 1 | ||||||||||||||||||||||||||||||||||||||
| 79 | # srpmpath: $RPMDIR/SRPMS/perl-Foo-Bar-1.23-1mga2008.0.src.rpm | ||||||||||||||||||||||||||||||||||||||
| 80 | # specpath: $RPMDIR/SPECS/perl-Foo-Bar.spec | ||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $status->mk_accessors(qw[ distname distvers extra_files rpmname rpmpath | |||||||||||||||||||||||||||||||||||||
| 82 | rpmvers srpmpath specpath ]); | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub prepare { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $status = $self->status; # private hash | |||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $module = $self->parent; # CPANPLUS::Module | |||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $intern = $module->parent; # CPANPLUS::Internals | |||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $conf = $intern->configure_object; # CPANPLUS::Configure | |||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM | |||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | # parse args. | ||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my %opts = ( | |||||||||||||||||||||||||||||||||||||
| 99 | force => $conf->get_conf('force'), # force rebuild | ||||||||||||||||||||||||||||||||||||||
| 100 | perl => $^X, | ||||||||||||||||||||||||||||||||||||||
| 101 | verbose => $conf->get_conf('verbose'), | ||||||||||||||||||||||||||||||||||||||
| 102 | %args, | ||||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | # dry-run with makemaker: find build prereqs. | ||||||||||||||||||||||||||||||||||||||
| 106 | 0 | msg( "dry-run prepare with makemaker..." ); | |||||||||||||||||||||||||||||||||||||
| 107 | 0 | $self->SUPER::prepare( %args ); | |||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | # compute & store package information | ||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $distname = $module->package_name; | |||||||||||||||||||||||||||||||||||||
| 111 | 0 | $status->distname( $distname ); | |||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $distvers = $module->package_version; | |||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $distext = $module->package_extension; | |||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $distsummary = _module_summary($module); | |||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $distdescr = _module_description($module); | |||||||||||||||||||||||||||||||||||||
| 116 | #my $distlicense = | ||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($disttoplevel) = $module->name=~ /([^:]+)::/; | |||||||||||||||||||||||||||||||||||||
| 118 | 0 | my @reqs = sort { $a cmp $b} ( | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | keys(%{ $module->status->prereqs }), | |||||||||||||||||||||||||||||||||||||
| 120 | 0 | keys(%{ $self->find_configure_requires }), | |||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my ($distbuild, $distmaker, $distinstall); | |||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if (-e _path_to_makefile_pl($module)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | push @reqs, 'Module::Build::Compat' if _is_module_build_compat($module); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $distbuild = "%{__perl} Makefile.PL INSTALLDIRS=vendor\n"; | |||||||||||||||||||||||||||||||||||||
| 128 | 0 | $distmaker = "%make"; | |||||||||||||||||||||||||||||||||||||
| 129 | 0 | $distinstall = "%make_install"; | |||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||
| 131 | # module::build only distribution | ||||||||||||||||||||||||||||||||||||||
| 132 | # The double dashes ("--") are for Module::Build::Tiny compatibility: | ||||||||||||||||||||||||||||||||||||||
| 133 | # * https://rt.cpan.org/Ticket/Display.html?id=86240 | ||||||||||||||||||||||||||||||||||||||
| 134 | # * https://wiki.mageia.org/en/Perl_policy | ||||||||||||||||||||||||||||||||||||||
| 135 | 0 | push @reqs, 'Module::Build'; | |||||||||||||||||||||||||||||||||||||
| 136 | 0 | $distbuild = "%{__perl} Build.PL --installdirs=vendor\n"; | |||||||||||||||||||||||||||||||||||||
| 137 | 0 | $distmaker = "./Build"; | |||||||||||||||||||||||||||||||||||||
| 138 | 0 | $distinstall = "./Build install --destdir=%{buildroot}"; | |||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $distbreqs = join "\n", map { "BuildRequires: perl($_)" } | |||||||||||||||||||||||||||||||||||||
| 141 | 0 | grep { $_ ne "perl" } @reqs; | |||||||||||||||||||||||||||||||||||||
| 142 | my @docfiles = | ||||||||||||||||||||||||||||||||||||||
| 143 | uniq | ||||||||||||||||||||||||||||||||||||||
| 144 | grep { | ||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | ( /^[A-Z.]+$/ && !/^MANIFEST/ ) || | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
/^[A-Z.]+$/ && !/^MANIFEST/ || /^(Change(s|log)|META.(json|yml)|(ex|s)amples?|e[gx]|demos?)$/i
/^[A-Z.]+$/ and not /^MANIFEST/
MC/DC0%0/3
/^[A-Z.]+$/ && !/^MANIFEST/ || /^(Change(s|log)|META.(json|yml)|(ex|s)amples?|e[gx]|demos?)$/i
/^[A-Z.]+$/
not /^MANIFEST/
/^(Change(s|log)|META.(json|yml)|(ex|s)amples?|e[gx]|demos?)$/i
Truth table0%0/5
A and not(B) || C
A= /^[A-Z.]+$/B= not /^MANIFEST/C= /^(Change(s|log)|META.(json|yml)|(ex|s)amples?|e[gx]|demos?)$/i
| |||||||||||||||||||||||||||||||||||||||
| 146 | m{^(Change(s|log)|META.(json|yml)|(ex|s)amples?|e[gx]|demos?)$}i | ||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||
| 148 | 0 | map { basename $_ } | |||||||||||||||||||||||||||||||||||||
| 149 | 0 | grep { m!^[^/]+/[^/]+$! } # only interested in root files | |||||||||||||||||||||||||||||||||||||
| 150 | 0 | @{ $module->status->files }; | |||||||||||||||||||||||||||||||||||||
| 151 | my $distarch = | ||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | defined( first { /\.(c|xs)$/i } @{ $module->status->files } ) | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 153 | ? 'BuildRequires: perl-devel' | ||||||||||||||||||||||||||||||||||||||
| 154 | : 'BuildArch: noarch'; | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $rpmname = _mk_pkg_name($distname); | |||||||||||||||||||||||||||||||||||||
| 157 | 0 | $status->rpmname( $rpmname ); | |||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | # check whether package has been build. | ||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ( my $pkg = $self->_has_been_build($rpmname, $distvers) ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $modname = $module->module; | |||||||||||||||||||||||||||||||||||||
| 163 | 0 | msg( "already created package for '$modname' at '$pkg'" ); | |||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ( not $opts{force} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 166 | 0 | msg( "won't re-spec package since --force isn't in use" ); | |||||||||||||||||||||||||||||||||||||
| 167 | # c::d::mga store | ||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $status->rpmpath($pkg); # store the path of rpm | |||||||||||||||||||||||||||||||||||||
| 169 | # cpanplus api | ||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $status->prepared(1); | |||||||||||||||||||||||||||||||||||||
| 171 | 0 | $status->created(1); | |||||||||||||||||||||||||||||||||||||
| 172 | 0 | $status->dist($pkg); | |||||||||||||||||||||||||||||||||||||
| 173 | 0 | return $pkg; | |||||||||||||||||||||||||||||||||||||
| 174 | # XXX check if it works | ||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||
| 177 | 0 | msg( '--force in use, re-specing anyway' ); | |||||||||||||||||||||||||||||||||||||
| 178 | # FIXME: bump rpm version | ||||||||||||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||||||||||||
| 180 | 0 | msg( "writing specfile for '$distname'..." ); | |||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||
| 183 | # compute & store path of specfile. | ||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $spec = "$RPMDIR{spec}/$rpmname.spec"; | |||||||||||||||||||||||||||||||||||||
| 185 | 0 | $status->specpath($spec); | |||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $vers = $module->version; | |||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||
| 189 | # writing the spec file. | ||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $tmpl = _template_spec_file_path(); | |||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | open my $tmplfh, '<', $tmpl or die "can't open '$tmpl': $!"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||
| 193 | 0 | POSIX::setlocale(&POSIX::LC_ALL, 'C'); | |||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $specfh; | |||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ( not open $specfh, '>', $spec ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 196 | 0 | error( "can't open '$spec': $!" ); | |||||||||||||||||||||||||||||||||||||
| 197 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | while ( defined( my $line = <$tmplfh> ) ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | last if $line =~ /^__END__$/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $line =~ s/DISTNAME/$distname/; | |||||||||||||||||||||||||||||||||||||
| 203 | 0 | $line =~ s/DISTVERS/$distvers/g; | |||||||||||||||||||||||||||||||||||||
| 204 | 0 | $line =~ s/DISTSUMMARY/$distsummary/; | |||||||||||||||||||||||||||||||||||||
| 205 | 0 | $line =~ s/DISTEXTENSION/$distext/; | |||||||||||||||||||||||||||||||||||||
| 206 | 0 | $line =~ s/DISTBUILDBUILDER/$distbuild/; | |||||||||||||||||||||||||||||||||||||
| 207 | 0 | $line =~ s/DISTINSTALL/$distinstall/; | |||||||||||||||||||||||||||||||||||||
| 208 | 0 | $line =~ s/DISTARCH/$distarch/; | |||||||||||||||||||||||||||||||||||||
| 209 | 0 | $line =~ s/DISTMAKER/$distmaker/; | |||||||||||||||||||||||||||||||||||||
| 210 | 0 | $line =~ s/DISTBUILDREQUIRES/$distbreqs/; | |||||||||||||||||||||||||||||||||||||
| 211 | 0 | $line =~ s/DISTDESCR/$distdescr/; | |||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $line =~ s/DISTDOC/@docfiles ? "%doc @docfiles" : ''/e; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $line =~ s/DISTTOPLEVEL/$disttoplevel/; | |||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $line =~ s/DISTEXTRA/join( "\n", @{ $status->extra_files || [] })/e; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$status->extra_files || []
MC/DC0%0/1
$status->extra_files || []
$status->extra_files
Truth table0%0/2
A
A= $status->extra_files
| |||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $line =~ s/DISTDATE/POSIX::strftime("%a %b %d %Y", localtime())/e; | |||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||
| 217 | 0 | print $specfh $line; | |||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||
| 219 | 0 | close $specfh; | |||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | # copy package. | ||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $basename = basename $module->status->fetch; | |||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $tarball = "$RPMDIR{source}/$basename"; | |||||||||||||||||||||||||||||||||||||
| 224 | 0 | copy( $module->status->fetch, $tarball ); | |||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||
| 226 | 0 | msg( "specfile for '$distname' written" ); | |||||||||||||||||||||||||||||||||||||
| 227 | # return success | ||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $status->prepared(1); | |||||||||||||||||||||||||||||||||||||
| 229 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=6 SCAR=36.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $status = $self->status; # private hash | |||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $module = $self->parent; # CPANPLUS::Module | |||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $intern = $module->parent; # CPANPLUS::Internals | |||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $conf = $intern->configure_object; # CPANPLUS::Configure | |||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM | |||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||
| 242 | # parse args. | ||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my %opts = ( | |||||||||||||||||||||||||||||||||||||
| 244 | force => $conf->get_conf('force'), # force rebuild | ||||||||||||||||||||||||||||||||||||||
| 245 | perl => $^X, | ||||||||||||||||||||||||||||||||||||||
| 246 | verbose => $conf->get_conf('verbose'), | ||||||||||||||||||||||||||||||||||||||
| 247 | %args, | ||||||||||||||||||||||||||||||||||||||
| 248 | ); | ||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | # check if we need to rebuild package. | ||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ( $status->created && defined $status->dist ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$status->created and defined $status->dist
MC/DC0%0/2
$status->created and defined $status->dist
$status->created
defined $status->dist
Truth table0%0/3
A and B
A= $status->createdB= defined $status->dist
| |||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ( not $opts{force} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 253 | 0 | msg( "won't re-build package since --force isn't in use" ); | |||||||||||||||||||||||||||||||||||||
| 254 | 0 | return $status->dist; | |||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||
| 256 | 0 | msg( '--force in use, re-building anyway' ); | |||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | RPMBUILD: { | ||||||||||||||||||||||||||||||||||||||
| 260 | # dry-run with makemaker: handle prereqs. | ||||||||||||||||||||||||||||||||||||||
| 261 | 0 | msg( 'dry-run build with makemaker...' ); | |||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self->SUPER::create( %args ); | |||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $spec = $status->specpath; | |||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $distname = $status->distname; | |||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $rpmname = $status->rpmname; | |||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||
| 269 | 0 | msg( "building '$distname' from specfile..." ); | |||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||
| 271 | # dry-run, to see if we forgot some files | ||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my ($buffer, $success); | |||||||||||||||||||||||||||||||||||||
| 273 | DRYRUN: { | ||||||||||||||||||||||||||||||||||||||
| 274 | 0 | local $ENV{LC_ALL} = 'C'; | |||||||||||||||||||||||||||||||||||||
| 275 | $success = run( | ||||||||||||||||||||||||||||||||||||||
| 276 | command => "rpmbuild -ba --quiet $spec", | ||||||||||||||||||||||||||||||||||||||
| 277 | verbose => $opts{verbose}, | ||||||||||||||||||||||||||||||||||||||
| 278 | 0 | buffer => \$buffer, | |||||||||||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||
| 282 | # check if the dry-run finished correctly | ||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if ( $success ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | my ($rpm) = (sort glob "$RPMDIR{rpm}/*/$rpmname-*.rpm")[0]; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ($srpm) = (sort glob "$RPMDIR{srcrpm}/$rpmname-*.src.rpm")[-1]; | |||||||||||||||||||||||||||||||||||||
| 286 | 0 | msg( "rpm created successfully: $rpm" ); | |||||||||||||||||||||||||||||||||||||
| 287 | 0 | msg( "srpm available: $srpm" ); | |||||||||||||||||||||||||||||||||||||
| 288 | # c::d::mga store | ||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $status->rpmpath($rpm); | |||||||||||||||||||||||||||||||||||||
| 290 | 0 | $status->srpmpath($srpm); | |||||||||||||||||||||||||||||||||||||
| 291 | # cpanplus api | ||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $status->created(1); | |||||||||||||||||||||||||||||||||||||
| 293 | 0 | $status->dist($rpm); | |||||||||||||||||||||||||||||||||||||
| 294 | 0 | return $rpm; | |||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||
| 297 | # unknown error, aborting. | ||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ( not $buffer =~ /^\s+Installed .but unpackaged. file.s. found:\n(.*)\z/ms ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 299 | 0 | error( "failed to create mageia package for '$distname': $buffer" ); | |||||||||||||||||||||||||||||||||||||
| 300 | # cpanplus api | ||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $status->created(0); | |||||||||||||||||||||||||||||||||||||
| 302 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | # additional files to be packaged | ||||||||||||||||||||||||||||||||||||||
| 306 | 0 | msg( "extra files installed, fixing spec file" ); | |||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $files = $1; | |||||||||||||||||||||||||||||||||||||
| 308 | 0 | $files =~ s/^\s+//mg; # remove spaces | |||||||||||||||||||||||||||||||||||||
| 309 | 0 | my @files = split /\n/, $files; | |||||||||||||||||||||||||||||||||||||
| 310 | 0 | $status->extra_files( \@files ); | |||||||||||||||||||||||||||||||||||||
| 311 | 0 | $self->prepare( %opts, force => 0 ); | |||||||||||||||||||||||||||||||||||||
| 312 | 0 | msg( 'restarting build phase' ); | |||||||||||||||||||||||||||||||||||||
| 313 | 0 | redo RPMBUILD; | |||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub install { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
install: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $status = $self->status; # private hash | |||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $module = $self->parent; # CPANPLUS::Module | |||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $intern = $module->parent; # CPANPLUS::Internals | |||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $conf = $intern->configure_object; # CPANPLUS::Configure | |||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM | |||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||
| 327 | # parse args. | ||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my %opts = ( | |||||||||||||||||||||||||||||||||||||
| 329 | verbose => $conf->get_conf('verbose'), | ||||||||||||||||||||||||||||||||||||||
| 330 | %args, | ||||||||||||||||||||||||||||||||||||||
| 331 | ); | ||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $rpm = $self->status->rpmpath; | |||||||||||||||||||||||||||||||||||||
| 335 | 0 | msg( "installing $rpm" ); | |||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | # install the rpm | ||||||||||||||||||||||||||||||||||||||
| 338 | # sudo is used, which means sudoers should be properly configured. | ||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my ($buffer, $success); | |||||||||||||||||||||||||||||||||||||
| 340 | INSTALL: { | ||||||||||||||||||||||||||||||||||||||
| 341 | 0 | local $ENV{LC_ALL} = 'C'; | |||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | my $sudo = $> == 0 ? '' : 'sudo'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 343 | $success = run( | ||||||||||||||||||||||||||||||||||||||
| 344 | command => "$sudo rpm -Uv $rpm", | ||||||||||||||||||||||||||||||||||||||
| 345 | verbose => $opts{verbose}, | ||||||||||||||||||||||||||||||||||||||
| 346 | 0 | buffer => \$buffer, | |||||||||||||||||||||||||||||||||||||
| 347 | ); | ||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||
| 350 | # check if the install finished correctly | ||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ( $success ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 352 | 0 | msg("successfully installed $rpm"); | |||||||||||||||||||||||||||||||||||||
| 353 | 0 | $status->installed(1); | |||||||||||||||||||||||||||||||||||||
| 354 | } else { | ||||||||||||||||||||||||||||||||||||||
| 355 | 0 | error("error while installing $rpm"); | |||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||
| 360 | # -- private methods | ||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||
| 362 | # | ||||||||||||||||||||||||||||||||||||||
| 363 | # my $bool = $self->_has_been_build; | ||||||||||||||||||||||||||||||||||||||
| 364 | # | ||||||||||||||||||||||||||||||||||||||
| 365 | # return true if there's already a package build for this module. | ||||||||||||||||||||||||||||||||||||||
| 366 | # | ||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | sub _has_been_build { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_been_build: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 368 | 0 | my ($self, $name, $vers) = @_; | |||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $pkg = ( sort glob "$RPMDIR{rpm}/*/$name-$vers-*.rpm" )[-1]; | |||||||||||||||||||||||||||||||||||||
| 370 | 0 | return $pkg; | |||||||||||||||||||||||||||||||||||||
| 371 | # FIXME: should we check cooker? | ||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||
| 375 | # -- private subs | ||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||
| 377 | # | ||||||||||||||||||||||||||||||||||||||
| 378 | # my $path = _path_to_makefile_pl(); | ||||||||||||||||||||||||||||||||||||||
| 379 | # | ||||||||||||||||||||||||||||||||||||||
| 380 | # return the path to the extracted makefile.pl | ||||||||||||||||||||||||||||||||||||||
| 381 | # | ||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | sub _path_to_makefile_pl { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_path_to_makefile_pl: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $module = shift; | |||||||||||||||||||||||||||||||||||||
| 384 | 0 | return $module->_status->extract . '/Makefile.PL'; | |||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||
| 388 | # | ||||||||||||||||||||||||||||||||||||||
| 389 | # my $bool = _is_module_build_compat(); | ||||||||||||||||||||||||||||||||||||||
| 390 | # | ||||||||||||||||||||||||||||||||||||||
| 391 | # return true if shipped makefile.pl is auto-generated with | ||||||||||||||||||||||||||||||||||||||
| 392 | # module::build::compat usage. | ||||||||||||||||||||||||||||||||||||||
| 393 | # | ||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub _is_module_build_compat { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_module_build_compat: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my ($module) = @_; | |||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $makefile = _path_to_makefile_pl($module); | |||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $content = slurp($makefile); | |||||||||||||||||||||||||||||||||||||
| 398 | 0 | return $content =~ /Module::Build::Compat/; | |||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||
| 402 | # | ||||||||||||||||||||||||||||||||||||||
| 403 | # my $path = _template_spec_file_path(); | ||||||||||||||||||||||||||||||||||||||
| 404 | # | ||||||||||||||||||||||||||||||||||||||
| 405 | # return the absolute path where the template spec will be located. | ||||||||||||||||||||||||||||||||||||||
| 406 | # | ||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub _template_spec_file_path { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_template_spec_file_path: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $path = dist_dir('CPANPLUS-Dist-Mageia'); | |||||||||||||||||||||||||||||||||||||
| 409 | 0 | return "$path/template.spec"; | |||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||
| 413 | # | ||||||||||||||||||||||||||||||||||||||
| 414 | # my $name = _mk_pkg_name($dist); | ||||||||||||||||||||||||||||||||||||||
| 415 | # | ||||||||||||||||||||||||||||||||||||||
| 416 | # given a distribution name, return the name of the mageia rpm | ||||||||||||||||||||||||||||||||||||||
| 417 | # package. in most cases, it will be the same, but some pakcage name | ||||||||||||||||||||||||||||||||||||||
| 418 | # will be too long as a rpm name: we'll have to cut it. | ||||||||||||||||||||||||||||||||||||||
| 419 | # | ||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | sub _mk_pkg_name { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_pkg_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my ($dist) = @_; | |||||||||||||||||||||||||||||||||||||
| 422 | 0 | my $name = 'perl-' . $dist; | |||||||||||||||||||||||||||||||||||||
| 423 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||
| 428 | # | ||||||||||||||||||||||||||||||||||||||
| 429 | # my $description = _module_description($module); | ||||||||||||||||||||||||||||||||||||||
| 430 | # | ||||||||||||||||||||||||||||||||||||||
| 431 | # given a cpanplus::module, try to extract its description from the | ||||||||||||||||||||||||||||||||||||||
| 432 | # embedded pod in the extracted files. this would be the first paragraph | ||||||||||||||||||||||||||||||||||||||
| 433 | # of the DESCRIPTION head1. | ||||||||||||||||||||||||||||||||||||||
| 434 | # | ||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | sub _module_description { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_module_description: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my ($module) = @_; | |||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $path = dirname $module->_status->extract; # where tarball has been extracted | |||||||||||||||||||||||||||||||||||||
| 439 | my @docfiles = | ||||||||||||||||||||||||||||||||||||||
| 440 | 0 | map { "$path/$_" } # prepend extract directory | |||||||||||||||||||||||||||||||||||||
| 441 | 0 | sort { length $a <=> length $b } # sort by length: we prefer top-level module description | |||||||||||||||||||||||||||||||||||||
| 442 | 0 | grep { /\.(pod|pm)$/ } # filter out those that can contain pod | |||||||||||||||||||||||||||||||||||||
| 443 | 0 | @{ $module->_status->files }; # list of embedded files | |||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||
| 445 | # parse file, trying to find a header | ||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $parser = Pod::POM->new; | |||||||||||||||||||||||||||||||||||||
| 447 | DOCFILE: | ||||||||||||||||||||||||||||||||||||||
| 448 | 0 | foreach my $docfile ( @docfiles ) { | |||||||||||||||||||||||||||||||||||||
| 449 | 0 | my $pom = $parser->parse_file($docfile); # try to find some pod | |||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | next DOCFILE unless defined $pom; # the file may contain no pod, that's ok | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 451 | HEAD1: | ||||||||||||||||||||||||||||||||||||||
| 452 | 0 | foreach my $head1 ($pom->head1) { | |||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | next HEAD1 unless $head1->title eq 'DESCRIPTION'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my $pom = $head1->content; # get pod for DESCRIPTION paragraph | |||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $text = $pom->present('Pod::POM::View::Text'); # transform pod to text | |||||||||||||||||||||||||||||||||||||
| 456 | 0 | my @paragraphs = split /\n\n/, $text; # split into paragraphs | |||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | splice @paragraphs, 3 if @paragraphs > 3; # only the 3 first paragraphs | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 458 | 0 | return join "\n\n", @paragraphs; | |||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||
| 462 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||
| 466 | # | ||||||||||||||||||||||||||||||||||||||
| 467 | # my $summary = _module_summary($module); | ||||||||||||||||||||||||||||||||||||||
| 468 | # | ||||||||||||||||||||||||||||||||||||||
| 469 | # given a cpanplus::module, return its registered description (if any) | ||||||||||||||||||||||||||||||||||||||
| 470 | # or try to extract it from the embedded pod in the extracted files. | ||||||||||||||||||||||||||||||||||||||
| 471 | # | ||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | sub _module_summary { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_module_summary: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my ($module) = @_; | |||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||
| 475 | # registered modules won't go farther... | ||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my $summary = $module->description; | |||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if (!$summary) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 479 | 0 | my $path = dirname $module->_status->extract; # where tarball has been extracted | |||||||||||||||||||||||||||||||||||||
| 480 | my @docfiles = | ||||||||||||||||||||||||||||||||||||||
| 481 | 0 | map { "$path/$_" } # prepend extract directory | |||||||||||||||||||||||||||||||||||||
| 482 | 0 | sort { length $a <=> length $b } # sort by length: we prefer top-level module summary | |||||||||||||||||||||||||||||||||||||
| 483 | 0 | grep { /\.(pod|pm)$/ } # filter out those that can contain pod | |||||||||||||||||||||||||||||||||||||
| 484 | 0 | @{ $module->_status->files }; # list of files embedded | |||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||
| 486 | # parse file, trying to find a header | ||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $parser = Pod::POM->new; | |||||||||||||||||||||||||||||||||||||
| 488 | DOCFILE: | ||||||||||||||||||||||||||||||||||||||
| 489 | 0 | foreach my $docfile ( @docfiles ) { | |||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $pom = $parser->parse_file($docfile); # try to find some pod | |||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | next unless defined $pom; # the file may contain no pod, that's ok | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 492 | HEAD1: | ||||||||||||||||||||||||||||||||||||||
| 493 | 0 | foreach my $head1 ($pom->head1) { | |||||||||||||||||||||||||||||||||||||
| 494 | # continue till we find '=head1 NAME' | ||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my $title = $head1->title; | |||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | next HEAD1 unless $title eq 'NAME'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 497 | # extract the description in NAME section | ||||||||||||||||||||||||||||||||||||||
| 498 | 0 | my $content = $head1->content; | |||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | next DOCFILE unless $content =~ /^[^-]+ - (.*)$/m; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | $summary = $1 if $content; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | if (!$summary) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 506 | 0 | $summary = 'no summary found'; | |||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||
| 509 | # summary must begin with an uppercase, without any final dot | ||||||||||||||||||||||||||||||||||||||
| 510 | # (this is a rpmlint policy) | ||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $summary =~ s/^(.)/\u$1/; | |||||||||||||||||||||||||||||||||||||
| 512 | 0 | $summary =~ s/\.$//; | |||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||
| 514 | 0 | return $summary; | |||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||
| 517 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||
| 519 | __END__ | ||||||||||||||||||||||||||||||||||||||