blib/lib/Dist/Zilla/Plugin/AssertOS.pm

filter: Statementstmt 25.7% 18 / 70 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 3 / 9 Podpod 80.0% 4 / 5 totaltotal 22.3% 25 / 112 CC 16 SCAR 40.5
CC
16
Cov
19%
gather_files
110.0
setup_installer
42.0
register_prereqs
6.0
CRAP 57.2
↑ Summary
1 package Dist::Zilla::Plugin::AssertOS;
2 1 $Dist::Zilla::Plugin::AssertOS::VERSION = '0.08';
3 # ABSTRACT: Require that our distribution is running on a particular OS
4  
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 with 'Dist::Zilla::Role::FileGatherer';
7 1 with 'Dist::Zilla::Role::InstallTool';
8 1 with 'Dist::Zilla::Role::MetaProvider';
9 1 with 'Dist::Zilla::Role::PrereqSource';
10  
11 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub mvp_multivalue_args { qw/os/ }
Subroutine mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod documented
14  
15 has 'os' => (
16 is => 'ro',
17 isa => 'ArrayRef',
18 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 1 auto_deref => 1,
20 );
21  
22 1 has 'bundle' => (
23 is => 'ro',
24 isa => 'Bool',
25 default => 1,
26 );
27  
28 0 ▶sub metadata {
Subroutine metadata: not called CC=1 SCAR=6.9
Pod documented
29 return {
30 0 no_index => {
31 directory => [ 'inc' ],
32 }
33 };
34 }
35  
36 0 ▶sub register_prereqs {
Subroutine register_prereqs: not called CC=2 SCAR=17.9
Pod undocumented
37 0 my $self = shift;
38 0 ▶ return if $self->bundle;
Branch: 1 branch
BranchTrueFalseTotal
if $self->bundle 0 0 0
39 0 $self->zilla->register_prereqs(
40 {
41 phase => 'configure',
42 type => 'requires',
43 },
44 'Devel::CheckOS' => '1.63',
45 'Devel::AssertOS' => '0',
46 );
47 }
48  
49 0 ▶sub gather_files {
Subroutine gather_files: not called CC=10 SCAR=47.0
Pod documented
50 0 my $self = shift;
51  
52 0 ▶ return unless $self->bundle;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->bundle 0 0 0
53  
54 0 require Data::Compare;
55  
56 0 foreach my $os ( $self->os ) {
57 0 my $oldinc = { map { $_ => $INC{$_} } keys %INC }; # clone
58 0 eval "use Devel::AssertOS qw($os)";
59 0 ▶ if(Data::Compare::Compare(\%INC, $oldinc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (Data::Compare::Compare(\%INC, $oldinc)) 0 0 0
60 0 print STDERR "Couldn't find a module for $os\n";
61 0 exit(1);
62 }
63 }
64  
65 0 ▶ my @modulefiles = keys %{{map { $_ => $INC{$_} } grep { /Devel/i && /(Check|Assert)OS/i } keys %INC}};
Condition0%0/3
/Devel/i && /(Check|Assert)OS/i
!ll&&!rl&&r
000
MC/DC0%0/2
/Devel/i && /(Check|Assert)OS/i
/Devel/i /(Check|Assert)OS/i
Truth table0%0/3
A && B
A= /Devel/iB= /(Check|Assert)OS/i
ABresult
0X0
100
111
66  
67 0 foreach my $modulefile (@modulefiles) {
68 0 my $fullfilename = '';
69 0 SEARCHINC: foreach (@INC) {
70 0 ▶ if(-e File::Spec->catfile($_, $modulefile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "File::Spec"->catfile($_, $modulefile)) 0 0 0
71 0 $fullfilename = File::Spec->catfile($_, $modulefile);
72 0 last SEARCHINC;
73 }
74 }
75 0 ▶ die("Can't find a file for $modulefile\n") unless(-e $fullfilename);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $fullfilename 0 0 0
76  
77 0 (my $module = join('::', split(/\W+/, $modulefile))) =~ s/::pm/.pm/;
78 0 my @dircomponents = ('inc', (split(/::/, $module)));
79 0 my $file = pop @dircomponents;
80  
81 {
82 0 ▶ open(my $PM, $fullfilename) ||
Branch: 1 branch
BranchTrueFalseTotal
open my $PM, $fullfilename or die "Can't read ${fullfilename}: $!" 0 0 0
83 die("Can't read $fullfilename: $!");
84 0 local $/ = undef;
85 0 (my $content = <$PM>) =~ s/package Devel::/package #\nDevel::/;
86 0 close($PM);
87  
88 0 my $pm = Dist::Zilla::File::InMemory->new({
89 content => $content,
90 name => File::Spec->catfile(@dircomponents, $file),
91 });
92  
93 0 $self->add_file($pm);
94  
95 }
96 }
97 0 return;
98 }
99  
100 # XXX - this should really be a separate phase that runs after InstallTool -
101 # until then, all we can do is die if we are run too soon
102 0 ▶sub setup_installer {
Subroutine setup_installer: not called CC=6 SCAR=37.4
Pod documented
103 0 my $self = shift;
104  
105 0 ▶ my @mfpl = grep { $_->name eq 'Makefile.PL' or $_->name eq 'Build.PL' } @{ $self->zilla->files };
Condition0%0/3
$_->name eq 'Makefile.PL' || $_->name eq 'Build.PL'
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->name eq 'Makefile.PL' || $_->name eq 'Build.PL'
$_->name eq 'Makefile.PL' $_->name eq 'Build.PL'
Truth table0%0/3
A || B
A= $_->name eq 'Makefile.PL'B= $_->name eq 'Build.PL'
ABresult
1X1
011
000
106  
107 0 ▶ $self->log_fatal('No Makefile.PL or Build.PL was found. [AssertOS] should appear in dist.ini after [MakeMaker] or [ModuleBuild]!') unless @mfpl;
Branch: 1 branch
BranchTrueFalseTotal
unless @mfpl 0 0 0
108  
109 0 for my $mfpl ( @mfpl ) {
110 0 my $content = qq{};
111 0 ▶ $content .= qq/use if ! ( grep { \$_ eq '.' } \@INC ), qw[lib .];\n/ if $self->bundle;
Branch: 1 branch
BranchTrueFalseTotal
if $self->bundle 0 0 0
112 0 ▶ $content .= qq{use lib 'inc';\n} if $self->bundle;
Branch: 1 branch
BranchTrueFalseTotal
if $self->bundle 0 0 0
113 0 $content .= qq{use Devel::AssertOS qw[};
114 0 $content .= join ' ', $self->os;
115 0 $content .= "];\n";
116 0 $mfpl->content( $content . $mfpl->content );
117 }
118 0 return;
119 }
120  
121 1 __PACKAGE__->meta->make_immutable;
122 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124 1 qq[run run Reynard];
125  
126 __END__
↑ Summary