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