Simple/Scaffold.pm

filter: Statementstmt 30.0% 21 / 70 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 26.7% 27 / 101 CC 11 SCAR 44.5
CC
11
Cov
23%
_cmd_scaffold
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 85.8
↑ Summary Simple.pm »
1 package CLI::Simple::Scaffold;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use CLI::Simple::Helpers qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 17 our @EXPORT_OK = qw(_cmd_scaffold);
13  
14 17 our $VERSION = '2.6.0';
15  
16 ########################################################################
17 0 ▶sub _cmd_scaffold {
Subroutine _cmd_scaffold: not called CC=11 SCAR=48.8
18 ########################################################################
19 0 my ( $class, $commands, $option_specs ) = @_;
20  
21 0 require Archive::Tar;
22 0 require YAML::Tiny;
23  
24 0 my $spec_file = $ARGV[1];
25  
26 0 my ( $spec, $effective_class );
27  
28 0 ▶ if ( $spec_file && -e $spec_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec_file and -e $spec_file) { } 0 0 0
Condition0%0/3
$spec_file and -e $spec_file
!ll&&!rl&&r
000
MC/DC0%0/2
$spec_file and -e $spec_file
$spec_file -e $spec_file
Truth table0%0/3
A and B
A= $spec_fileB= -e $spec_file
ABresult
0X0
100
111
29 0 $spec = YAML::Tiny::LoadFile($spec_file);
30  
31 # derive class from spec filename: cpan-maker-bootstrapper.yml -> Cpan::Maker::Bootstrapper
32 0 ( my $stem = $spec_file ) =~ s/[.]ya?ml\z//xsm;
33 0 $effective_class = join '::', map { ucfirst $_ } split /-/xsm, $stem;
34 }
35 else {
36 0 my $yaml = _generate_spec_yaml( $class, $commands, $option_specs, $TRUE );
37 0 $spec = YAML::Tiny::Load($yaml);
38 0 $effective_class = $class;
39 }
40  
41 # use effective_class for all naming
42 0 my $tarball = _tarball_filename($effective_class);
43 0 my $dist = _class_to_filename($effective_class);
44  
45 0 my $tar = Archive::Tar->new;
46  
47 0 my $main_stub = _main_module_stub($effective_class);
48  
49 0 my $source_path = _find_module_path($effective_class);
50  
51 0 ▶ if ( $source_path && -e $source_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_path and -e $source_path) 0 0 0
Condition0%0/3
$source_path and -e $source_path
!ll&&!rl&&r
000
MC/DC0%0/2
$source_path and -e $source_path
$source_path -e $source_path
Truth table0%0/3
A and B
A= $source_pathB= -e $source_path
ABresult
0X0
100
111
52 0 local $RS = undef;
53  
54 0 ▶ open my $fh, '<', $source_path or die "ERROR: $OS_ERROR\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $source_path or die "ERROR: $CLI::Simple::Scaffold::OS_ERROR\n" 0 0 0
55 0 my $pod = _extract_pod(<$fh>);
56 0 close $fh;
57 0 ▶ if ($pod) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pod) 0 0 0
58 0 $main_stub .= "\n$pod";
59 }
60 0 ▶ $main_stub .= "\n" if $main_stub !~ /\n\z/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $main_stub =~ /\n\z/msx 0 0 0
61 }
62  
63 0 $tar->add_data( _pm_path($effective_class), $main_stub );
64  
65 0 my %seen_roles;
66  
67 0 for my $cmd ( sort keys %{ $spec->{commands} } ) {
68 0 my $value = $spec->{commands}{$cmd};
69 0 ▶ my $role = _is_class_name($value) ? $value : _sub_to_role( $effective_class, $value );
Branch: 1 branch
BranchTrueFalseTotal
_is_class_name($value) ? : 0 0 0
70  
71 0 ▶ next if $seen_roles{$role}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_roles{$role}++ 0 0 0
72  
73 # derive method name from role class, not command key
74 # Pod::Extract::Role::Extract -> Extract -> cmd_extract
75 0 ( my $method_suffix = $role ) =~ s/\A.*::Role:://xsm;
76 0 $method_suffix =~ s/::/_/gxsm;
77 0 my $method = 'cmd_' . lc $method_suffix;
78  
79 0 $tar->add_data( _pm_path($role), _role_stub( $role, $method, $effective_class ) );
80 }
81  
82 # spec yaml into share/
83 0 $tar->add_data( "$dist.yml", YAML::Tiny::Dump($spec), );
84  
85 # help out the bootstrapper...
86 0 my @role_paths = map { _pm_path($_); } keys %seen_roles;
87  
88 0 my $main_pm = _pm_path($effective_class);
89  
90 0 ( my $role_dir = $effective_class ) =~ s|::|/|gxsm;
91 0 $role_dir = "lib/$role_dir/Role";
92  
93 0 my $project_mk = <<"END_MK";
94 # inter-module dependencies
95 \$(eval \$(call find-files,ROLES,$role_dir,*.pm.in))
96  
97 $main_pm: \\
98 \$(ROLES)
99 END_MK
100  
101 0 $tar->add_data( 'project.mk', $project_mk );
102 0 $tar->write( $tarball, Archive::Tar::COMPRESS_GZIP() );
103  
104 0 printf {*STDOUT} "created %s\n", $tarball;
105  
106 0 return $SUCCESS;
107 }
108  
109 17 1;
110  
111 __END__
↑ Summary Simple.pm »