File Coverage

/root/.cpan/build/Devel-CheckOS-2.04-0/bin/use-devel-assertos
Criterion Covered Total %
statement 91 93 97.8
branch 32 46 69.5
condition 3 3 100.0
subroutine 7 7 100.0
pod n/a
total 133 149 89.2


line stmt bran cond sub pod time code
1             #!perl
2              
3 7     7   38193 use strict;
  7         12  
  7         407  
4             # NB no warnings because of "implicit split to @_"
5              
6 7         538692 $/ = undef;
7              
8 7     7   38 use File::Spec;
  7         12  
  7         3563  
9              
10 7         23 my @files = grep { -f $_ } qw(Makefile.PL Build.PL);
  14         362  
11              
12 7 50       77 (my @oses = @ARGV) || die("You must specify at least one OS\n");
13              
14 7     7   535 eval "use Devel::AssertOS"; # to load AssertOS and CheckOS
  7         4063  
  7         32  
  7         45  
15              
16 7         23 my $verbose = 1;
17 7 100       30 if($oses[0] eq '-q') { # mostly to make tests shut the hell up
18 6         12 $verbose = 0;
19 6         15 shift @oses;
20             }
21              
22 7 100       56 if($oses[0] eq '-l') {
23 1         4 print join(', ', Devel::CheckOS::list_platforms())."\n";
24 1         0 exit(0);
25             }
26              
27              
28 6 100       237 if(!-e 'MANIFEST') {
29 4 50       642 open(MANIFEST, '>>MANIFEST') || die("Can't update MANIFEST\n");
30 4         26 print MANIFEST "MANIFEST\n";
31 4         267 close(MANIFEST);
32             }
33 6 100       34 if(!@files) { # neither Makefile.PL no Build.PL exists, so create Makefile.PL
34 3 50       82 open(MANIFEST, '>>MANIFEST') || die("Can't update MANIFEST\n");
35 3         10 print MANIFEST "Makefile.PL\n";
36 3         120 close(MANIFEST);
37             }
38              
39 6 100       28 push @files, 'Makefile.PL' unless(@files);
40              
41             # NB can't just use scalar list_platforms cos that won't tell us that,
42             # eg, Linux::v2_6 also uses Linux
43 6         20 foreach my $os (@oses) {
44 12         1001 my %oldinc = %INC;
45 12     6   1291 eval "use Devel::AssertOS qw($os)";
  6     5   40  
  6     1   12  
  6         28  
  5         45  
  5         11  
  5         48  
  1         6  
  1         1  
  1         6  
46 12 50       799 if(
47 901         2757 join(':', map { $_ => $oldinc{$_} } sort keys %oldinc) eq
48 958         2445 join(':', map { $_ => $INC{$_} } sort keys %INC)
49             ) {
50 0         0 print STDERR "Couldn't find a module for $os\n";
51 0         0 exit(1);
52             }
53             }
54 6         22 my @modulefiles = keys %{{
55 69         189 map { $_ => $INC{$_} }
56             grep {
57 6 100 100     96 /\bDevel\b/i &&
  501         1812  
58             /\b(Check|Assert)OS\b/i &&
59             $_ !~ /\bAlias\b/i
60             }
61             keys %INC
62             }};
63              
64 6         1096 mkdir 'inc';
65 6         1623 mkdir 'inc/Devel';
66 6         508 mkdir 'inc/Devel/AssertOS';
67 6 50       41 print "Extra directories created under inc/\n" if($verbose);
68              
69 6 50       256 open(MANIFEST, '>>MANIFEST') || die("Can't update MANIFEST\n");
70 7     7   5077 use Data::Dumper;
  7         74199  
  7         17507  
71 6         28 foreach my $modulefile (@modulefiles) {
72 69         130 my $fullfilename = '';
73 69         137 SEARCHINC: foreach (@INC) {
74 138 100       2786 if(-e File::Spec->catfile($_, $modulefile)) {
75 69         414 $fullfilename = File::Spec->catfile($_, $modulefile);
76 69         190 last SEARCHINC;
77             }
78             }
79 69 50       769 die("Can't find a file for $modulefile\n") unless(-e $fullfilename);
80              
81 69         662 (my $module = join('::', split(/\W+/, $modulefile))) =~ s/::pm/.pm/;
82 69         250 my @dircomponents = ('inc', (split(/::/, $module)));
83 69         109 my $file = pop @dircomponents;
84              
85 69         887 mkdir File::Spec->catdir(@dircomponents);
86            
87 69 50       1832 open(PM, $fullfilename) ||
88             die("Can't read $fullfilename: $!");
89 69         1573 (my $pm = ) =~ s/package Devel::/package #\nDevel::/;
90 69         480 close(PM);
91 69 50       8037 open(PM, '>'.File::Spec->catfile(@dircomponents, $file)) ||
92             die("Can't write ".File::Spec->catfile(@dircomponents, $file).": $!");
93 69         608 print PM $pm;
94 69 50       169 print "Copied $fullfilename to\n ".File::Spec->catfile(@dircomponents, $file)."\n" if($verbose);
95 69         2535 close(PM);
96              
97 69         445 print MANIFEST join('/', @dircomponents, $file)."\n";
98             }
99 6         204 close(MANIFEST);
100 6 50       35 print "Added necessary modules\n" if($verbose);
101 6 50       23 print "Updated MANIFEST\n" if($verbose);
102              
103 6         27 foreach my $file (@files) {
104 7         21 my $contents = '';
105 7 100       181 if(open(FILE, $file)) { $contents = ; close(FILE); }
  4         106  
  4         34  
106 7 50       667 open(FILE, ">$file") || die("Can't write $file\n");
107             print FILE 'use lib qw(inc); use Devel::AssertOS qw('.
108             join(' ',
109 8         48 sort { $a cmp $b } map {
110 7         38 exists($Devel::CheckOS::OS_ALIASES{$_})
111 14 100       108 ? $Devel::CheckOS::OS_ALIASES{$_}
112             : $_
113             } @oses
114             ).
115             ");\n\n";
116 7         21 print FILE $contents;
117 7         813 close(FILE);
118 7 50       11 print "Modified $file\n" if($verbose);
119             }
120              
121             =head1 NAME
122              
123             use-devel-assertos - a script to package Devel::AssertOS modules
124             with your code.
125              
126             =head1 DESCRIPTION
127              
128             This script, when run in the directory in which your shiny new module
129             lives, will bundle whichever Devel::AssertOS modules you ask it to
130             in the C directory, and update your Makefile.PL (or Build.PL)
131             appropriately. If neither exists, it will create a Makefile.PL.
132             The MANIFEST file is updated if any files are created.
133              
134             =head1 SYNOPSIS
135              
136             use-devel-assertos NetBSD OpenBSD FreeBSD
137              
138             But note that if you use C you are encouraged to use
139             C instead.
140              
141             =head1 USAGE
142              
143             In the example above, this will insert code to make your module
144             depend on one of the specified OSes, as well as update Makefile.PL /
145             Build.PL / MANIFEST. By default it's rather noisy, but you can
146             suppress that by passing -q as the first parameter.
147              
148             =head1 SUPPORTED PLATFORMS
149              
150             To get a list of supported platforms, do this:
151              
152             use-devel-assertos -l
153              
154             =head1 WARNINGS, BUGS and FEEDBACK
155              
156             This script has not been thoroughly tested. You should check by
157             hand that it has done what you expected after running it.
158              
159             If you use Module::Build::Compat to write a Makefile.PL, then you
160             will need to re-run this script whenever you have generated a new
161             Makefile.PL.
162              
163             I welcome feedback about my code, including constructive criticism.
164             Bug reports should be made using L.
165              
166             =head1 SEE ALSO
167              
168             L
169              
170             L
171              
172             L
173              
174             =head1 AUTHOR
175              
176             David Cantrell EFE
177              
178             =head1 COPYRIGHT and LICENCE
179              
180             Copyright 2024 David Cantrell
181              
182             This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively.
183              
184             =head1 CONSPIRACY
185              
186             This software is also free-as-in-mason.
187              
188             =cut