blib/lib/CPANPLUS/Dist/Fedora.pm

filter: Statementstmt 17.5% 48 / 273 Branchbran 1.9% 1 / 52 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 41.6% 15 / 36 Podpod 100% 5 / 5 totaltotal 18.6% 70 / 376 CC 34 SCAR 30.1
CC
34
Cov
15%
_module_summary
72.0
create
42.0
prepare
30.0
CRAP 20.2
↑ Summary Build »
1 #
2 # This file is part of CPANPLUS::Dist::Fedora.
3 # Copyright (c) 2007 Jerome Quelin, all rights reserved.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
7 #
8  
9 package CPANPLUS::Dist::Fedora;
10 3 $CPANPLUS::Dist::Fedora::VERSION = '0.4.0';
11 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use parent 'CPANPLUS::Dist::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use Cwd qw[ cwd ];
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use CPANPLUS::Error qw[ error msg ];
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use File::Basename qw[ basename dirname ];
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use File::Copy qw[ copy ];
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use IPC::Cmd qw[ run can_run ];
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use List::Util qw[ first min ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Path::Tiny qw[ path ];
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Pod::POM ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Pod::POM::View::Text ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use POSIX qw[ strftime ];
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use Template ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 3 $CPANPLUS::Dist::Fedora::_testme = 0;
29  
30 sub _get_spec_perl_exe
31 {
32 0 ▶ return 'perl';
Subroutine _get_spec_perl_exe: not called CC=1 SCAR=6.9
33 }
34  
35 sub _get_spec_template
36 {
37 # Dealing with DATA gets increasingly messy, IMHO
38 # So we're going to use the Template Toolkit instead
39 0 ▶ return <<'END_SPEC';
Subroutine _get_spec_template: not called CC=1 SCAR=6.9
40 [% BLOCK rpm_req_wrap %][%- rpm_prefix %] [% rpm_req(br) -%][%- IF (brs.$br != 0) %] >= [% brs.$br %][% END -%][%- "\n" -%][% END %]
41 Name: [% status.rpmname %]
42 Version: [% status.distvers %]
43 Release: [% status.rpmvers %]%{?dist}
44 License: [% status.license %]
45 Group: Development/Libraries
46 Summary: [% status.summary %]
47 Source: http://search.cpan.org/CPAN/[% module.path %]/[% status.distname %]-%{version}.[% module.package_extension %]
48 Url: http://metacpan.org/release/[% status.distname %]
49 Requires: perl(:MODULE_COMPAT_%(eval "`[% perl_exe %] -V:version`"; echo $version))
50 [% IF status.is_noarch %]BuildArch: noarch[% END %]
51 [% brs = buildreqs; FOREACH br = brs.keys.sort -%]
52 [% INCLUDE rpm_req_wrap br = br , rpm_prefix = "Requires:" %]
53 [% END -%]
54 BuildRequires: coreutils
55 BuildRequires: make
56 BuildRequires: perl(ExtUtils::MakeMaker)
57 BuildRequires: perl-devel
58 BuildRequires: perl-generators
59 BuildRequires: perl-interpreter
60 [% FOREACH br = brs.keys.sort -%]
61 [% INCLUDE rpm_req_wrap br = br , rpm_prefix = "BuildRequires:" %]
62 [% END -%]
63  
64  
65 %description
66 [% status.description -%]
67  
68  
69 %prep
70 %setup -q -n [% status.distname %]-%{version}
71  
72 %build
73 [% IF (!status.is_noarch) -%]
74 [% perl_exe %] Makefile.PL INSTALLDIRS=vendor OPTIMIZE="%{optflags}" INSTALLVENDORLIB=%{perl_vendorlib} INSTALLVENDORMAN3DIR=%{_mandir}/man3
75 [% ELSE -%]
76 [% perl_exe %] Makefile.PL INSTALLDIRS=vendor INSTALLVENDORLIB=%{perl_vendorlib} INSTALLVENDORMAN3DIR=%{_mandir}/man3
77 [% END -%]
78 %{make_build}
79  
80 %install
81 %{make_install}
82 find %{buildroot} -type f \( -name .packlist -o -name perllocal.pod \) -exec rm -f {} ';'
83 [% IF (!status.is_noarch) -%]
84 find %{buildroot} -type f -name '*.bs' -a -size 0 -exec rm -f {} ';'
85 [% END -%]
86 find %{buildroot} -depth -type d -exec rmdir {} 2>/dev/null ';'
87  
88 %{_fixperms} %{buildroot}/*
89  
90 %check
91 make test
92  
93 %files
94 %defattr(-,root,root,-)[% "\n" %]
95 [%- IF licensefiles %]%license [% licensefiles _ "\n" %][%- END -%]
96 %doc [% docfiles %]
97 [% IF (status.is_noarch) -%]
98 %{perl_vendorlib}/*
99 [% ELSE -%]
100 %{perl_vendorarch}/*
101 %exclude %dir %{perl_vendorarch}/auto
102 [% END -%]
103 %{_mandir}/man3/*.3*
104 [% distextra %]
105  
106 %changelog
107 * [% date %] [% packager %] [% status.distvers %]-[% status.rpmvers %]
108 - initial Fedora packaging
109 - generated with cpan2dist (CPANPLUS::Dist::Fedora version [% packagervers %])
110 END_SPEC
111 }
112  
113 #--
114 # class methods
115  
116 #
117 # my $bool = CPANPLUS::Dist::Fedora->format_available;
118 #
119 # Return a boolean indicating whether or not you can use this package to
120 # create and install modules in your environment.
121 #
122 sub format_available
123 {
124 # Check Fedora release file
125 2 ▶ if ( not( -f '/etc/fedora-release' or -f '/etc/redhat-release' ) )
Subroutine format_available: called CC=5 SCAR=25.7
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "/etc/fedora-release" or -f "/etc/redhat-release") 2 0 2
Condition33%1/3
-f "/etc/fedora-release" or -f "/etc/redhat-release"
l!l&&r!l&&!r
002
MC/DC0%0/2
-f "/etc/fedora-release" or -f "/etc/redhat-release"
-f "/etc/fedora-release" -f "/etc/redhat-release"
Truth table33%1/3
A or B
A= -f "/etc/fedora-release"B= -f "/etc/redhat-release"
ABresult
1X1
011
000
126 {
127 2 error('Not on a Fedora system');
128 2 return;
129 }
130  
131 0 my $flag;
132  
133 # check prereqs
134 0 for my $prog (qw[ rpm rpmbuild gcc ])
135 {
136 0 ▶ next if can_run($prog);
Branch: 1 branch
BranchTrueFalseTotal
if can_run($prog) 0 0 0
137 0 error("'$prog' is a required program to build Fedora packages");
138 0 $flag++;
139 }
140  
141 0 return not $flag;
142 }
143  
144 #--
145 # public methods
146  
147 #
148 # my $bool = $fedora->init;
149 #
150 # Sets up the C<CPANPLUS::Dist::Fedora> object for use, and return true if
151 # everything went fine.
152 #
153 sub init
154 {
155 0 ▶ my ($self) = @_;
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
156 0 my $status = $self->status; # an Object::Accessor
157 # distname: Foo-Bar
158 # distvers: 1.23
159 # extra_files: qw[ /bin/foo /usr/bin/bar ]
160 # rpmname: perl-Foo-Bar
161 # rpmpath: $RPMDIR/RPMS/noarch/perl-Foo-Bar-1.23-1mdv2008.0.noarch.rpm
162 # rpmvers: 1
163 # rpmdir: $DIR
164 # srpmpath: $RPMDIR/SRPMS/perl-Foo-Bar-1.23-1mdv2008.0.src.rpm
165 # specpath: $RPMDIR/SPECS/perl-Foo-Bar.spec
166 # is_noarch: true if pure-perl
167 # license: try to figure out the actual license
168 # summary: one-liner summary
169 # description: a paragraph summary or so
170 0 $status->mk_accessors(
171 qw[ distname distvers extra_files rpmname rpmpath rpmvers rpmdir
172 srpmpath specpath is_noarch license summary description
173 ]
174 );
175  
176 # This is done to initialise it.
177 0 $self->_get_current_dir();
178  
179 0 return 1;
180 }
181  
182 sub _calc_spec_text
183 {
184 0 ▶ my $self = shift;
Subroutine _calc_spec_text: not called CC=4 SCAR=30.0
185 0 my $module = $self->parent; # CPANPLUS::Module
186 0 my $tmpl = Template->new( { EVAL_PERL => 1 } );
187 0 my $status = $self->status; # Private hash
188  
189 0 my @files = @{ $module->status->files };
190  
191 my @basenames =
192 0 map { basename $_ } @files;
193  
194 # Files for %doc
195 my @docfiles =
196 0 grep { /(?:README|Change(?:s|log))$/i } @basenames;
197  
198 my @licensefiles =
199 0 grep { /(?:LICENSE)$/i } @basenames;
200 0 my $spec_template = $self->_get_spec_template();
201  
202 0 my $spec_text = '';
203  
204 # Handle build/test/requires
205 0 my $buildreqs = $module->status->prereqs;
206 0 ▶ $buildreqs->{'Module::Build::Compat'} = 0
Branch: 1 branch
BranchTrueFalseTotal
if _is_module_build_compat($module) 0 0 0
207 if _is_module_build_compat($module);
208  
209 # Process template into spec
210 $tmpl->process(
211 \$spec_template,
212 {
213 status => $status,
214 module => $module,
215 buildreqs => $buildreqs,
216 date => strftime( "%a %b %d %Y", localtime ),
217 perl_exe => $self->_get_spec_perl_exe(),
218 packager => $self->_get_packager(),
219 docfiles => join( ' ', @docfiles ),
220 licensefiles => join( ' ', @licensefiles ),
221 rpm_req => sub {
222 0 ▶ my $br = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
223 0 ▶ return ( ( $br eq 'perl' ) ? $br : "perl($br)" );
Branch: 1 branch
BranchTrueFalseTotal
$br eq 'perl' ? : 0 0 0
224 },
225  
226 packagervers => $CPANPLUS::Dist::Fedora::VERSION,
227 0 ▶ distextra => join( "\n", @{ $status->extra_files || [] } ),
Branch: 1 branch
BranchTrueFalseTotal
$status->extra_files or [] 0 0 0
228 },
229 \$spec_text,
230 );
231  
232 0 my $ret = +{ text => $spec_text, };
233 0 ▶ if ($CPANPLUS::Dist::Fedora::_testme)
Branch: 1 branch
BranchTrueFalseTotal
if ($CPANPLUS::Dist::Fedora::_testme) 0 0 0
234 {
235 0 die $ret;
236 }
237 0 return $ret;
238 }
239  
240 sub prepare
241 {
242 0 ▶ my ( $self, %args ) = @_;
Subroutine prepare: not called CC=5 SCAR=34.0
Pod documented
243 0 msg("dry-run prepare with makemaker...");
244 0 $self->SUPER::prepare(%args);
245 0 my $status = $self->status; # Private hash
246 0 my $module = $self->parent; # CPANPLUS::Module
247 0 my $intern = $module->parent; # CPANPLUS::Internals
248 0 my $conf = $intern->configure_object; # CPANPLUS::Configure
249 0 my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM
250  
251 # Parse args.
252 0 my %opts = (
253 force => $conf->get_conf('force'), # force rebuild
254 perl => $^X,
255 verbose => $conf->get_conf('verbose'),
256 %args,
257 );
258  
259 # Dry-run with makemaker: find build prereqs.
260 0 if (0)
261 {
262 msg("dry-run prepare with makemaker...");
263 $self->SUPER::prepare(%args);
264 }
265  
266 # Compute & store package information
267 0 my $distname = $module->package_name;
268 0 $status->distname($distname);
269 0 $status->distvers( $module->package_version );
270 0 $status->summary( _module_summary($module) );
271 0 $status->description( _module_description($module) );
272 0 $status->license( $self->_module_license($module) );
273  
274 #$status->disttop($module->name=~ /([^:]+)::/);
275 0 my $dir = $status->rpmdir( $self->_get_current_dir() );
276 0 $status->rpmvers(1);
277  
278 # Cache files
279 0 my @files = @{ $module->status->files };
280  
281 # Figure out if we're noarch or not
282 $status->is_noarch(
283 do
284 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
do { &first(sub { /\.(c|xs)$/i; } , @files) } ? : 0 0 0
285 0 ▶ first { /\.(c|xs)$/i } @files;
Subroutine __ANON__: not called CC=1 SCAR=6.9
286 }
287 ? 0
288 : 1
289 );
290  
291 0 my $rpmname = _mk_pkg_name($distname);
292 0 $status->rpmname($rpmname);
293  
294 # check whether package has been build.
295 0 ▶ if ( my $pkg = $self->_has_been_built( $rpmname, $status->distvers ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = $self->_has_been_built($rpmname, $status->distvers)) { } 0 0 0
296 {
297 0 my $modname = $module->module;
298 0 msg("already created package for '$modname' at '$pkg'");
299  
300 0 ▶ if ( not $opts{force} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"force"}) 0 0 0
301 {
302 0 msg("won't re-spec package since --force isn't in use");
303  
304 # c::d::mdv store
305 0 $status->rpmpath($pkg); # store the path of rpm
306 # cpanplus api
307 0 $status->prepared(1);
308 0 $status->created(1);
309 0 $status->dist($pkg);
310 0 return $pkg;
311  
312 # XXX check if it works
313 }
314  
315 0 msg('--force in use, re-specing anyway');
316  
317 # FIXME: bump rpm version
318 }
319 else
320 {
321 0 msg("writing specfile for '$distname'...");
322 }
323  
324 # Compute & store path of specfile.
325 0 $status->specpath("$dir/$rpmname.spec");
326  
327 # Prepare our template
328 0 my $text = $self->_calc_spec_text()->{text};
329 0 my $specpath = path( $status->specpath );
330 0 $specpath->spew_utf8($text);
331 0 print "spec file written $specpath\n";
332  
333 0 ▶ if ( $intern->_callbacks->munge_dist_metafile )
Branch: 1 branch
BranchTrueFalseTotal
if ($intern->_callbacks->munge_dist_metafile) 0 0 0
334 {
335 0 print 'munging...';
336  
337 0 my $orig_contents = _read_file( $status->specpath );
338 0 my $new_contents = $intern->_callbacks->munge_dist_metafile->(
339 $intern, $orig_contents
340 );
341 0 _write_file( $status->specpath, $new_contents );
342 }
343  
344 # copy package.
345 0 my $tarball = "$dir/" . basename $module->status->fetch;
346 0 copy $module->status->fetch, $tarball;
347  
348 0 msg("specfile for '$distname' written");
349  
350 # return success
351 0 $status->prepared(1);
352 0 return 1;
353 }
354  
355 sub create
356 {
357 0 ▶ my ( $self, %args ) = @_;
Subroutine create: not called CC=6 SCAR=37.4
Pod documented
358 0 my $status = $self->status; # private hash
359 0 my $module = $self->parent; # CPANPLUS::Module
360 0 my $intern = $module->parent; # CPANPLUS::Internals
361 0 my $conf = $intern->configure_object; # CPANPLUS::Configure
362 0 my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM
363  
364 # parse args.
365 0 my %opts = (
366 force => $conf->get_conf('force'), # force rebuild
367 perl => $^X,
368 verbose => $conf->get_conf('verbose'),
369 %args,
370 );
371  
372 # check if we need to rebuild package.
373 0 ▶ if ( $status->created && defined $status->dist )
Branch: 1 branch
BranchTrueFalseTotal
if ($status->created and defined $status->dist) 0 0 0
Condition0%0/3
$status->created and defined $status->dist
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
374 {
375 0 ▶ if ( not $opts{force} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"force"}) 0 0 0
376 {
377 0 msg("won't re-build package since --force isn't in use");
378 0 return $status->dist;
379 }
380 0 msg('--force in use, re-building anyway');
381 }
382  
383 RPMBUILD:
384 {
385 # dry-run with makemaker: handle prereqs.
386 0 msg('dry-run build with makemaker...');
387 0 $self->SUPER::create(%args);
388  
389 0 my $spec = $status->specpath;
390 0 my $distname = $status->distname;
391 0 my $rpmname = $status->rpmname;
392  
393 0 msg("Building '$distname' from specfile $spec...");
394  
395 # dry-run, to see if we forgot some files
396 0 my ( $buffer, $success );
397 0 my $dir = $status->rpmdir;
398 DRYRUN:
399 {
400 0 local $ENV{LC_ALL} = 'C';
401 $success = run(
402  
403 #command => "rpmbuild -ba --quiet $spec",
404 command => 'rpmbuild -ba '
405 . qq{--define '_sourcedir $dir' }
406 . qq{--define '_builddir $dir' }
407 . qq{--define '_srcrpmdir $dir' }
408 . qq{--define '_rpmdir $dir' }
409 . $spec,
410 verbose => $opts{verbose},
411 0 buffer => \$buffer,
412 );
413 }
414  
415 # check if the dry-run finished correctly
416 0 ▶ if ($success)
Branch: 1 branch
BranchTrueFalseTotal
if ($success) 0 0 0
417 {
418 0 my ($rpm) = ( sort glob "$dir/*/$rpmname-*.rpm" )[-1];
419 0 my ($srpm) = ( sort glob "$dir/$rpmname-*.src.rpm" )[-1];
420 0 msg("RPM created successfully: $rpm");
421 0 msg("SRPM available: $srpm");
422  
423 # c::d::mdv store
424 0 $status->rpmpath($rpm);
425 0 $status->srpmpath($srpm);
426  
427 # cpanplus api
428 0 $status->created(1);
429 0 $status->dist($rpm);
430 0 return $rpm;
431 }
432  
433 # unknown error, aborting.
434 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($buffer =~ /^\s+Installed .but unpackaged. file.s. found:\n(.*)\z/ms) 0 0 0
435 not $buffer =~
436 /^\s+Installed .but unpackaged. file.s. found:\n(.*)\z/ms )
437 {
438 0 error("Failed to create Fedora package for '$distname': $buffer");
439  
440 # cpanplus api
441 0 $status->created(0);
442 0 return;
443 }
444  
445 # additional files to be packaged
446 0 msg("extra files installed, fixing spec file");
447 0 my $files = $1;
448 0 $files =~ s/^\s+//mg; # remove spaces
449 0 my @files = split /\n/, $files;
450 0 $status->extra_files( \@files );
451 0 $self->prepare( %opts, force => 1 );
452 0 msg('restarting build phase');
453 0 redo RPMBUILD;
454 }
455 }
456  
457 sub install
458 {
459 0 ▶ my ( $self, %args ) = @_;
Subroutine install: not called CC=1 SCAR=6.9
Pod documented
460 0 my $rpm = $self->status->rpm;
461 0 error("installing $rpm");
462 0 die;
463  
464 #$dist->status->installed
465 }
466  
467 #--
468 # Private methods:
469  
470 sub _read_file
471 {
472 0 ▶ my ($filename) = @_;
Subroutine _read_file: not called CC=1 SCAR=6.9
473 0 open my $fh, '< :encoding(utf8)', $filename;
474 0 local $/;
475 0 my $contents = <$fh>;
476 0 close($fh);
477  
478 0 return $contents;
479 }
480  
481 sub _write_file
482 {
483 0 ▶ my ( $filename, $contents ) = @_;
Subroutine _write_file: not called CC=1 SCAR=6.9
484 0 open my $fh, '> :encoding(utf8)', $filename;
485 0 print {$fh} $contents;
486 0 close($fh);
487  
488 0 return;
489 }
490  
491 #
492 # my $bool = $self->_has_been_built;
493 #
494 # Returns true if there's already a package built for this module.
495 #
496 sub _has_been_built
497 {
498 0 ▶ my ( $self, $name, $vers ) = @_;
Subroutine _has_been_built: not called CC=1 SCAR=6.9
499 0 my $RPMDIR = $self->_get_RPMDIR();
500 0 my $pkg = ( sort glob "$RPMDIR/RPMS/*/$name-$vers-*.rpm" )[-1];
501 0 return $pkg;
502  
503 # FIXME: should we check cooker?
504 }
505  
506 #--
507 # Private subs
508  
509 sub _is_module_build_compat
510 {
511 0 ▶ my ($module) = @_;
Subroutine _is_module_build_compat: not called CC=3 SCAR=24.8
512 0 my $makefile = $module->_status->extract . '/Makefile.PL';
513  
514 0 open my $mk_fh, "<", $makefile;
515  
516 0 my $found = 0;
517  
518 LINES:
519 0 ▶ while ( my $line = <$mk_fh> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $mk_fh)) 0 0 0
520 {
521 0 ▶ if ( $line =~ /Module::Build::Compat/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Module::Build::Compat/) 0 0 0
522 {
523 0 $found = 1;
524 0 last LINES;
525 }
526 }
527  
528 0 close($mk_fh);
529  
530 0 return $found;
531 }
532  
533 #
534 # my $name = _mk_pkg_name($dist);
535 #
536 # given a distribution name, return the name of the mandriva rpm
537 # package. in most cases, it will be the same, but some pakcage name
538 # will be too long as a rpm name: we'll have to cut it.
539 #
540 sub _mk_pkg_name
541 {
542 0 ▶ my ($dist) = @_;
Subroutine _mk_pkg_name: not called CC=1 SCAR=6.9
543 0 my $name = 'perl-' . $dist;
544 0 return $name;
545 }
546  
547 # determine the module license.
548 #
549 # FIXME! for now just return the default licence
550  
551 sub _module_license
552 {
553 0 ▶ my $self = shift;
Subroutine _module_license: not called CC=1 SCAR=6.9
554 0 my $module = shift;
555  
556 0 return $self->_get_default_license();
557 }
558  
559 sub _get_default_license
560 {
561 0 ▶ return 'CHECK(GPL+ or Artistic)';
Subroutine _get_default_license: not called CC=1 SCAR=6.9
562 }
563  
564 #
565 # my $description = _module_description($module);
566 #
567 # given a cpanplus::module, try to extract its description from the
568 # embedded pod in the extracted files. this would be the first paragraph
569 # of the DESCRIPTION head1.
570 #
571 sub _module_description
572 {
573 0 ▶ my ($module) = @_;
Subroutine _module_description: not called CC=5 SCAR=34.0
574  
575 0 my $path =
576 dirname $module->_status->extract; # where tarball has been extracted
577 my @docfiles =
578 0 map { "$path/$_" } # prepend extract directory
579 0 sort { length $a <=> length $b } # sort by length: we prefer top-level module description
580 0 grep { /\.(pod|pm)$/ } # filter out those that can contain pod
581 0 @{ $module->_status->files }; # list of embedded files
582  
583 # parse file, trying to find a header
584 0 my $parser = Pod::POM->new;
585 DOCFILE:
586 0 foreach my $docfile (@docfiles)
587 {
588 0 my $pom = $parser->parse_file($docfile); # try to find some pod
589 next DOCFILE
590 0 ▶ unless defined $pom; # the file may contain no pod, that's ok
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pom 0 0 0
591 HEAD1:
592 0 foreach my $head1 ( $pom->head1 )
593 {
594 0 ▶ next HEAD1 unless $head1->title eq 'DESCRIPTION';
Branch: 1 branch
BranchTrueFalseTotal
unless $head1->title eq "DESCRIPTION" 0 0 0
595 0 my $pom = $head1->content; # get pod for DESCRIPTION paragraph
596 0 my $text =
597 $pom->present('Pod::POM::View::Text'); # transform pod to text
598 0 my @paragraphs = ( split /\n\n/, $text );
599 0 @paragraphs = @paragraphs[ 0 .. min( $#paragraphs, 2 ) ]
600 ; # only the 3 first paragraphs
601 0 return join "\n\n", @paragraphs;
602 }
603 }
604  
605 0 return 'no description found';
606 }
607  
608 #
609 # my $summary = _module_summary($module);
610 #
611 # Given a CPANPLUS::Module, return its registered description (if any)
612 # or try to extract it from the embedded POD in the extracted files.
613 #
614 sub _module_summary
615 {
616 0 ▶ my ($module) = @_;
Subroutine _module_summary: not called CC=8 SCAR=42.8
617  
618 # registered modules won't go farther...
619 0 ▶ return $module->description if $module->description;
Branch: 1 branch
BranchTrueFalseTotal
if $module->description 0 0 0
620  
621 0 my $path =
622 dirname $module->_status->extract; # where tarball has been extracted
623 my @docfiles =
624 0 map { "$path/$_" } # prepend extract directory
625 0 sort { length $a <=> length $b } # sort by length: we prefer top-level module summary
626 0 grep { /\.(pod|pm)$/ } # filter out those that can contain pod
627 0 @{ $module->_status->files }; # list of files embedded
628  
629 # parse file, trying to find a header
630 0 my $parser = Pod::POM->new;
631 DOCFILE:
632 0 foreach my $docfile (@docfiles)
633 {
634 0 my $pom = $parser->parse_file($docfile); # try to find some pod
635 0 ▶ next unless defined $pom; # the file may contain no pod, that's ok
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pom 0 0 0
636 HEAD1:
637 0 foreach my $head1 ( $pom->head1 )
638 {
639 0 my $title = $head1->title;
640 0 ▶ next HEAD1 unless $title eq 'NAME';
Branch: 1 branch
BranchTrueFalseTotal
unless $title eq "NAME" 0 0 0
641 0 my $content = $head1->content;
642 0 ▶ next DOCFILE unless $content =~ /^[^-]+ - (.*)$/m;
Branch: 1 branch
BranchTrueFalseTotal
unless $content =~ /^[^-]+ - (.*)$/m 0 0 0
643 0 ▶ return $1 if $content;
Branch: 1 branch
BranchTrueFalseTotal
if $content 0 0 0
644 }
645 }
646  
647 0 return 'no summary found';
648 }
649  
650 sub _get_RPMDIR
651 {
652 0 ▶ my $self = shift;
Subroutine _get_RPMDIR: not called CC=2 SCAR=17.9
653  
654 # Memoize it.
655 0 ▶ if ( !defined( $self->{_RPMDIR} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_RPMDIR"}) 0 0 0
656 {
657 0 chomp( my $d = qx[ rpm --eval %_topdir ] );
658 0 $self->{_RPMDIR} = $d;
659 }
660  
661 0 return $self->{_RPMDIR};
662 }
663  
664 sub _get_packager
665 {
666 0 ▶ my $self = shift;
Subroutine _get_packager: not called CC=2 SCAR=17.9
667  
668 # Memoize it.
669 0 ▶ if ( !defined( $self->{_packager} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_packager"}) 0 0 0
670 {
671 0 my $d = `rpm --eval '%{packager}'`;
672 0 chomp $d;
673 0 $self->{_packager} = $d;
674 }
675  
676 0 return $self->{_packager};
677 }
678  
679 sub _get_current_dir
680 {
681 0 ▶ my $self = shift;
Subroutine _get_current_dir: not called CC=2 SCAR=17.9
682  
683 # Memoize it.
684 0 ▶ if ( !defined( $self->{_current_dir} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_current_dir"}) 0 0 0
685 {
686 0 $self->{_current_dir} = cwd();
687 }
688  
689 0 return $self->{_current_dir};
690 }
691  
692 3 1;
693  
694 __END__
↑ Summary Build »