| 1 | package Module::Install::AssertOS; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use base qw(Module::Install::Base); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | $VERSION = '0.12'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | sub assertos { | ||||||||||||||||||
|
Subroutine
assertos: called CC=3 SCAR=13.0
Pod
documented
| |||||||||||||||||||||
| 12 | 1 | my $self = shift; | |||||||||||||||||||
| 13 | 1 | my @oses = @_; | |||||||||||||||||||
| 14 | 1 | ▶ | return unless scalar @oses; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | ▶ | unless ( $Module::Install::AUTHOR ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 0 | require Devel::AssertOS; | |||||||||||||||||||
| 18 | 0 | Devel::AssertOS->import( @oses ); | |||||||||||||||||||
| 19 | 0 | return; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 1 | _author_side( @oses ); | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | ▶ | sub _author_side { | ||||||||||||||||||
|
Subroutine
_author_side: called CC=10 SCAR=23.2
| |||||||||||||||||||||
| 26 | 1 | my @oses = @_; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | require Data::Compare; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | foreach my $os (@oses) { | |||||||||||||||||||
| 31 | 1 | my $oldinc = { map { $_ => $INC{$_} } keys %INC }; # clone | |||||||||||||||||||
| 32 | 1 | ▶ | eval "use Devel::AssertOS qw($os)"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 1 | ▶ | if(Data::Compare::Compare(\%INC, $oldinc)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | print STDERR "Couldn't find a module for $os\n"; | |||||||||||||||||||
| 35 | 0 | exit(1); | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 1 | ▶ | my @modulefiles = keys %{{map { $_ => $INC{$_} } grep { /Devel/i && /(Check|Assert)OS/i } keys %INC}}; | ||||||||||||||||||
|
Condition100%3/3
/Devel/i && /(Check|Assert)OS/i
MC/DC100%2/2
/Devel/i && /(Check|Assert)OS/i
/Devel/i
/(Check|Assert)OS/i
Truth table100%3/3
A && B
A= /Devel/iB= /(Check|Assert)OS/i
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | mkdir 'inc'; | |||||||||||||||||||
| 41 | 1 | mkdir 'inc/Devel'; | |||||||||||||||||||
| 42 | 1 | mkdir 'inc/Devel/AssertOS'; | |||||||||||||||||||
| 43 | 1 | print "Extra directories created under inc/\n"; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 1 | foreach my $modulefile (@modulefiles) { | |||||||||||||||||||
| 46 | 4 | my $fullfilename = ''; | |||||||||||||||||||
| 47 | 4 | SEARCHINC: foreach (@INC) { | |||||||||||||||||||
| 48 | 20 | ▶ | if(-e File::Spec->catfile($_, $modulefile)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 4 | $fullfilename = File::Spec->catfile($_, $modulefile); | |||||||||||||||||||
| 50 | 4 | last SEARCHINC; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | 4 | ▶ | die("Can't find a file for $modulefile\n") unless(-e $fullfilename); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 4 | (my $module = join('::', split(/\W+/, $modulefile))) =~ s/::pm/.pm/; | |||||||||||||||||||
| 56 | 4 | my @dircomponents = ('inc', (split(/::/, $module))); | |||||||||||||||||||
| 57 | 4 | my $file = pop @dircomponents; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 4 | mkdir File::Spec->catdir(@dircomponents); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 4 | ▶ | open(PM, $fullfilename) || | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | die("Can't read $fullfilename: $!"); | ||||||||||||||||||||
| 63 | 4 | my $lsep = $/; | |||||||||||||||||||
| 64 | 4 | $/ = undef; | |||||||||||||||||||
| 65 | 4 | (my $pm = <PM>) =~ s/package Devel::/package #\nDevel::/; | |||||||||||||||||||
| 66 | 4 | close(PM); | |||||||||||||||||||
| 67 | 4 | $/ = $lsep; | |||||||||||||||||||
| 68 | 4 | ▶ | open(PM, '>'.File::Spec->catfile(@dircomponents, $file)) || | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | die("Can't write ".File::Spec->catfile(@dircomponents, $file).": $!"); | ||||||||||||||||||||
| 70 | 4 | print PM $pm; | |||||||||||||||||||
| 71 | 4 | print "Copied $fullfilename to\n ".File::Spec->catfile(@dircomponents, $file)."\n"; | |||||||||||||||||||
| 72 | 4 | close(PM); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 1 | return 1; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 3 | 'Assert this'; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||