App/Command/dumpphases.pm

filter: Statementstmt 96.6% 86 / 89 Branchbran 78.5% 11 / 14 Conditioncond 85.7% 6 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 92.8% 13 / 14 Podpod 100% 4 / 4 totaltotal 92.4% 122 / 132 CC 16 SCAR 16.6
CC
16
Cov
94%
execute
10.0
_available_themes
6.1
abstract
2.0
CRAP 5.3
↑ Summary dumpphases/Role/Theme/SimpleColor.pm »
1 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::App::Command::dumpphases;
6  
7 6 our $VERSION = '1.000009';
8  
9 # ABSTRACT: Dump a textual representation of each phase's parts.
10  
11 6 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25 6 ▶use Dist::Zilla::App '-command';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use Try::Tiny qw( try catch );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 ## no critic ( ProhibitAmbiguousNames)
30 0 ▶sub abstract { return 'Dump a textual representation of each phase\'s parts' }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
31 ## use critic
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63 5 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
64 5 return [ 'color-theme=s', 'color theme to use, ( eg: basic::blue )' ];
65 }
66  
67 5 ▶sub validate_args {
Subroutine validate_args: called CC=1 SCAR=0.0
Pod documented
68 5 my ( $self, $opt, undef ) = @_;
69 5 ▶ try {
Subroutine __ANON__: called CC=2 SCAR=6.9
70 5 ▶ $self->_load_color_theme( $opt->color_theme || 'basic::blue' );
Condition100%2/2
$opt->color_theme || 'basic::blue'
l!l
41
MC/DC100%1/1
$opt->color_theme || 'basic::blue'
$opt->color_theme
Truth table100%2/2
A
A= $opt->color_theme
Aresult
11
00
71 }
72 1 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 1 my $error = shift;
74 1 require Carp;
75 1 my $message = $error . qq[\n\n];
76 1 $message .= sprintf "^ Was seen attempting to load theme <%s>\n", $opt->color_theme;
77 1 $message .= sprintf 'available themes are: %s', ( join q{, }, $self->_available_themes );
78 1 Carp::croak($message);
79 5 };
80 4 return;
81 }
82  
83 1 ▶sub _available_themes {
Subroutine _available_themes: called CC=6 SCAR=18.1
84 1 my (undef) = @_;
85 1 require Path::ScanINC;
86 1 my (@theme_dirs) = Path::ScanINC->new()->all_dirs( 'Dist', 'Zilla', 'dumpphases', 'Theme' );
87 1 ▶ if ( not @theme_dirs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@theme_dirs) 0 1 1
88 0 require Carp;
89 ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
90 0 Carp::cluck('Found no theme dirs in @INC matching Dist/Zilla/dumpphases/Theme/');
91 }
92 1 my (%themes);
93 1 require Path::Tiny;
94 1 for my $dir (@theme_dirs) {
95 3 my $it = Path::Tiny->new($dir)->iterator(
96 {
97 recurse => 1,
98 follow_symlinks => 0,
99 },
100 );
101 3 ▶ while ( my $item = $it->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $item = &$it()) 15 3 18
102 15 ▶ next unless $item =~ /[.]pm\z/msx;
Branch: 1 branch
BranchTrueFalseTotal
unless $item =~ /[.]pm\z/msx 3 12 15
103 12 ▶ next if -d $item;
Branch: 1 branch
BranchTrueFalseTotal
if -d $item 0 12 12
104 12 my $theme_name = $item->relative($dir);
105 12 $theme_name =~ s{[.]pm\z}{}msx;
106 12 $theme_name =~ s{/}{::}msxg;
107 12 $themes{$theme_name} = 1;
108 }
109 }
110 ## no critic (Variables::ProhibitUnusedVarsStricter)
111 1 return ( my (@list) = sort keys %themes );
112 }
113  
114 9 ▶sub _load_color_theme {
Subroutine _load_color_theme: called CC=1 SCAR=0.0
115 9 my ( undef, $color_theme ) = @_;
116 9 require Module::Runtime;
117 9 my $theme_module = Module::Runtime::compose_module_name( 'Dist::Zilla::dumpphases::Theme', $color_theme );
118 9 Module::Runtime::require_module($theme_module);
119 8 return $theme_module;
120 }
121  
122 4 ▶sub execute {
Subroutine execute: called CC=10 SCAR=23.0
Pod documented
123 4 my ( $self, $opt, undef ) = @_;
124  
125 4 ▶ my $theme_module = $self->_load_color_theme( $opt->color_theme || 'basic::blue' );
Condition100%2/2
$opt->color_theme || 'basic::blue'
l!l
31
MC/DC100%1/1
$opt->color_theme || 'basic::blue'
$opt->color_theme
Truth table100%2/2
A
A= $opt->color_theme
Aresult
11
00
126 4 my $theme = $theme_module->new();
127  
128 4 my $seen_plugins = {};
129  
130 4 require Dist::Zilla::Util::RoleDB;
131 4 my $zilla;
132 4 for my $phase ( Dist::Zilla::Util::RoleDB->new()->phases ) {
133 96 my ($label);
134 96 $label = $phase->name;
135 96 $label =~ s/\A-//msx;
136 96 $label =~ s/([[:lower:]])([[:upper:]])/$1 $2/gmsx;
137  
138 96 my @plugins;
139 96 ▶ $zilla ||= $self->zilla;
Condition66%2/3
$zilla ||= $self->zilla
l!l&&r!l&&!r
9240
MC/DC0%0/2
$zilla ||= $self->zilla
$zilla $self->zilla
Truth table66%2/3
A ||= B
A= $zillaB= $self->zilla
ABresult
1X1
011
000
140 96 push @plugins, @{ $zilla->plugins_with( $phase->name ) };
141 96 ▶ next unless @plugins;
Branch: 1 branch
BranchTrueFalseTotal
unless @plugins 92 4 96
142  
143 4 $theme->print_section_header( 'Phase: ', $label );
144 4 $theme->print_section_prelude( 'description: ', $phase->description );
145 4 $theme->print_section_prelude( 'role: ', $phase->name );
146 4 $theme->print_section_prelude( 'phase_method: ', $phase->phase_method );
147  
148 4 for my $plugin (@plugins) {
149 4 $seen_plugins->{ $plugin->plugin_name } = 1;
150 4 $theme->print_star_assoc( $plugin->plugin_name, blessed($plugin) );
151 }
152 }
153 4 my @unrecognised;
154 4 for my $plugin ( @{ $zilla->plugins } ) {
155 44 ▶ next if exists $seen_plugins->{ $plugin->plugin_name };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$seen_plugins{$plugin->plugin_name} 4 40 44
156 40 push @unrecognised, $plugin;
157 }
158 4 ▶ if (@unrecognised) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unrecognised) 4 0 4
159 4 $theme->print_section_header( 'Unrecognised: ', 'Phase not known' );
160 4 $theme->print_section_prelude( 'description: ', 'These plugins exist but were not in any predefined phase to scan for' );
161 4 for my $plugin (@unrecognised) {
162 40 $theme->print_star_assoc( $plugin->plugin_name, blessed($plugin) );
163 }
164 }
165 4 return 0;
166 }
167  
168 6 1;
169  
170 __END__
↑ Summary dumpphases/Role/Theme/SimpleColor.pm »