| 1 | package Module::Setup::Devel; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use YAML (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Module::Setup::Distribute; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use Module::Setup::Path::Flavor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | my($class, $context) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my $self = bless { context => $context }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | weaken $self->{context}; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub context { shift->{context} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
context: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | sub run { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | return $self->test if $self->context->options->{test}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $self->pack if $self->context->options->{pack}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $self->create_skeleton; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | sub create_skeleton { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_skeleton: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $self->context->_load_argv( flavor_name => '' ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | Carp::croak "flavor class name is required" unless $self->context->options->{flavor_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $module = $self->context->options->{flavor_name}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my @pkg = split /::/, $module; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $module_path = join '-', @pkg; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $base_dir = Module::Setup::Path::Flavor->new($module_path); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $base_dir->path->subdir('t')->mkpath; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $base_dir->template->path->subdir('testdir')->mkpath; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $fh = $base_dir->template->path->file('testfile.txt')->openw; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | print $fh "hello! $module"; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $base_dir->create_flavor(+{ | |||||||||||||||||||||||||||||||||||||||||
| 47 | module_setup_flavor_devel => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | class => $module, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | plugins => [], | ||||||||||||||||||||||||||||||||||||||||||
| 50 | testdata => +{ | ||||||||||||||||||||||||||||||||||||||||||
| 51 | module => 'MyApp', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | files => [ | ||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | file => 'testfile.txt', | ||||||||||||||||||||||||||||||||||||||||||
| 55 | likes => ['hel+o', $module ], | ||||||||||||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 58 | dirs => ['testdir'], | ||||||||||||||||||||||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | sub load_config { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_config: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $conf = YAML::LoadFile('config.yaml'); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return unless $conf && ref($conf) eq 'HASH' && $conf->{module_setup_flavor_devel}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$conf and ref $conf eq "HASH" and $conf->{"module_setup_flavor_devel"}
$conf and ref $conf eq "HASH"
MC/DC0%0/3
$conf and ref $conf eq "HASH" and $conf->{"module_setup_flavor_devel"}
$conf
ref $conf eq "HASH"
$conf->{"module_setup_flavor_devel"}
Truth table0%0/4
A and B and C
A= $confB= ref $conf eq "HASH"C= $conf->{"module_setup_flavor_devel"}
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return $conf; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # make t/all.t && --pack && prove t/*t | ||||||||||||||||||||||||||||||||||||||||||
| 71 | sub test { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test: not called CC=11 SCAR=46.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $conf = $self->load_config; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return unless $conf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $distribute = Module::Setup::Distribute->new( $conf->{class}, %{ $self->context->options } ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my @files;my @file; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $test = $conf->{testdata}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | for my $data (@{ $test->{files} }) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | push @files, $data unless ref $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $like; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (@{ $data->{likes} }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my @likes = map { "qr/$_/" } map { s{/}{\\/}g; $_ } @{ $data->{likes} }; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $like = join ', ', @likes; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $str = " file '$data->{file}'"; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $str .= " => $like" if $like; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $str .= ";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | push @file, $str; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my @dirs; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | for my $data (@{ $test->{dirs} }) { | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | push @dirs, $data; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $code; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $code .= sprintf(" files qw( %s );\n", @files) if @files; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $code .= join "\n", @file if @file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $code .= sprintf(" dirs qw( %s );\n", @dirs) if @dirs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $module = 'DevelTestFlavor'; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $fh = $distribute->target_path->file('t', 'all.t')->openw; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | print $fh <<TEST__; | |||||||||||||||||||||||||||||||||||||||||
| 106 | use Module::Setup::Test::Flavor; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | run_flavor_test { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | default_dialog; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | name '$test->{module}'; | ||||||||||||||||||||||||||||||||||||||||||
| 111 | flavor '+$module'; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | $code}; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | TEST__ | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # create pack | ||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 40 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 40 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $pack; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | local *Module::Setup::stdout = sub { $pack = $_[1] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | local $self->context->options->{executable}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->pack($module); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | open my $fh, '>', "$module.pm" or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | print $fh $pack; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # prove -v | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | system 'prove', '-v'; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | sub pack { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $conf = $self->load_config; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return unless $conf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $class; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $class = $conf->{class}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $self->context->options->{flavor_dir} = '.'; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $self->context->options->{flavor} = $class; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->context->options->{module} = $class; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $self->context->pack_flavor; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | __END__ | ||||||||||||||||||||||||||||||||||||||||||