| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$cached //= $CACHE{$filename}{0}{$md5}
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}
| |||||||||||||||||||||||||||||
| 36 | 9 | ▶ | return $cached if $cached; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 8 | ▶ | open( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||