blib/lib/Dist/Zilla/Role/ModuleMetadata.pm

filter: Statementstmt 100% 39 / 39 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 90.7% 59 / 65 CC 8 SCAR 15.9
CC
8
Cov
91%
module_metadata_for_file
8.4
BEGIN
1.0
BEGIN
1.0
CRAP 4.9
↑ Summary
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Role::ModuleMetadata; # git description: v0.005-3-g1691291
4 # vim: set ts=8 sts=4 sw=4 tw=115 et :
5 # ABSTRACT: A role for plugins that use Module::Metadata
6 # KEYWORDS: zilla distribution plugin role metadata cache packages versions
7  
8 5 our $VERSION = '0.006';
9  
10 5 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Module::Metadata 1.000005;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Digest::MD5 'md5';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # filename => collect_pod? => md5 content => MMD object
16 5 my %CACHE;
17  
18 sub module_metadata_for_file
19 9 ▶{
Subroutine module_metadata_for_file: called CC=8 SCAR=21.2
Pod documented
20 9 my ($self, $file, @options) = @_;
21  
22 9 ▶ Carp::croak('missing file argument for module_metadata_for_file') if not $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 9 9
23  
24 # handle dzil v4 files by assuming no (or latin1) encoding
25 9 ▶ my $encoded_content = $file->can('encoded_content') ? $file->encoded_content : $file->content;
Branch: 1 branch
BranchTrueFalseTotal
$file->can('encoded_content') ? : 9 0 9
26  
27 9 my %mmd_options = ( collect_pod => 0, @options );
28  
29 # We cache on the MD5 checksum to detect if the file has been modified
30 # by some other plugin since it was last parsed, making our object invalid.
31 9 my $md5 = md5($encoded_content);
32 9 my $filename = $file->name;
33 # objects with collected pod are suitable for use when collect_pod was not requested.
34 9 my $cached = $CACHE{$filename}{1}{$md5};
35 9 ▶ $cached //= $CACHE{$filename}{0}{$md5} if not $mmd_options{collect_pod};
Branch: 1 branch
BranchTrueFalseTotal
unless $mmd_options{"collect_pod"} 7 2 9
Condition66%2/3
$cached //= $CACHE{$filename}{0}{$md5}
l!l&&r!l&&!r
106
MC/DC50%1/2
$cached //= $CACHE{$filename}{0}{$md5}
$cached $CACHE{$filename}{0}{$md5}
Truth table66%2/3
A //= B
A= $cachedB= $CACHE{$filename}{0}{$md5}
ABresult
1X1
011
000
36 9 ▶ return $cached if $cached;
Branch: 1 branch
BranchTrueFalseTotal
if $cached 1 8 9
37  
38 8 ▶ open(
Branch: 2 branches
BranchTrueFalseTotal
open my $fh, $file->can("encoding") ? sprintf("<:encoding(%s)", $file->encoding) : "<", \$encoded_content or $self->log_fatal(["cannot open handle to %s content: %s", $filename, $!]) 8 0 8
$file->can('encoding') ? : 8 0 8
39 my $fh,
40 ($file->can('encoding') ? sprintf('<:encoding(%s)', $file->encoding) : '<'),
41 \$encoded_content,
42 ) or $self->log_fatal([ 'cannot open handle to %s content: %s', $filename, $! ]);
43  
44 8 $self->log_debug([ 'parsing %s for Module::Metadata', $filename ]);
45  
46 8 my $mmd = Module::Metadata->new_from_handle($fh, $filename, %mmd_options);
47 8 return ($CACHE{$filename}{ $mmd_options{collect_pod} }{$md5} = $mmd);
48 }
49  
50 around dump_config => sub
51 3 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
52 3 my ($orig, $self) = @_;
53 3 my $config = $self->$orig;
54  
55 3 $config->{+__PACKAGE__} = {
56 'Module::Metadata' => Module::Metadata->VERSION,
57 version => $VERSION,
58 };
59  
60 3 return $config;
61 5 };
62  
63 5 1;
64  
65 __END__
↑ Summary