Iller/DocType/Cpanfile.pm

filter: Statementstmt 95.0% 58 / 61 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 4 totaltotal 89.5% 77 / 86 CC 10 SCAR 10.3
CC
10
Cov
94%
parse
5.0
to_string
5.0
to_hash
2.0
CRAP 2.8
« Iller/Role/HasPrereqs.pm ↑ Summary Iller/DocType/Global.pm »
1 2 ▶use 5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Iller::DocType::Cpanfile;
6  
7 2 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
8 # ABSTRACT: Turn the Dist::Iller config into a .cpanfile file
9 2 our $VERSION = '0.1411';
10  
11 2 ▶use Dist::Iller::Elk;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use JSON::MaybeXS qw/decode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Dist::Iller::Prereq;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 with qw/
17 Dist::Iller::DocType
18 Dist::Iller::Role::HasPrereqs
19 /;
20  
21 2 ▶sub comment_start { '#' }
Subroutine comment_start: called CC=1 SCAR=0.0
Pod undocumented
22  
23 3 ▶sub filename { 'cpanfile' }
Subroutine filename: called CC=1 SCAR=0.0
Pod undocumented
24  
25 4 ▶sub phase { 'after' }
Subroutine phase: called CC=1 SCAR=0.0
Pod undocumented
26  
27 0 ▶sub to_hash {
Subroutine to_hash: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my $self = shift;
29 0 return { prereqs => $self->prereqs };
30 }
31  
32 1 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.2
33 1 my $self = shift;
34  
35 1 my $metapath = path('META.json');
36 1 ▶ if(!$metapath->exists) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($metapath->exists) 0 1 1
37 0 croak 'META.json does not exist';
38 }
39  
40 1 my $meta = decode_json($metapath->slurp)->{'prereqs'};
41  
42 1 for my $phase (keys %{ $meta }) {
43 4 my $phasedata = $meta->{ $phase };
44  
45 4 for my $relation (keys %{ $phasedata }) {
46 6 my $relationdata = $phasedata->{ $relation };
47  
48 6 for my $module (sort keys %{ $relationdata }) {
49 115 my $prereq = $meta->{ $phase }{ $relation };
50 $self->add_prereq(Dist::Iller::Prereq->new(
51 module => $module,
52 115 version => $meta->{ $phase }{ $relation }{ $module },
53 phase => $phase,
54 relation => $relation,
55 ));
56 }
57 }
58 }
59 }
60  
61 1 ▶sub to_string {
Subroutine to_string: called CC=5 SCAR=16.1
62 1 my $self = shift;
63  
64 1 my @strings;
65  
66 1 for my $phase (qw/runtime test build configure develop/) {
67 RELATION:
68 5 for my $relation (qw/requires recommends suggests conflicts/) {
69  
70 20 ▶ my @prereqs = sort { $a->module cmp $b->module } $self->filter_prereqs(sub { $_->phase eq $phase && $_->relation eq $relation });
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_->phase eq $phase and $_->relation eq $relation 516 2064 2580
71 20 ▶ next RELATION if !scalar @prereqs;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @prereqs 13 7 20
72  
73 7 push @strings => "on $phase => sub {";
74 7 for my $prereq (@prereqs) {
75 129 push @strings => sprintf q{ %s '%s' => '%s';}, $relation, $prereq->module, $prereq->version;
76 }
77 7 push @strings => '};';
78 }
79 }
80 1 return join "\n" => (@strings, '');
81  
82 }
83  
84 2 __PACKAGE__->meta->make_immutable;
85  
86 2 1;
87  
88 __END__
« Iller/Role/HasPrereqs.pm ↑ Summary Iller/DocType/Global.pm »