Progcopy.PL

filter: Statementstmt 73.4% 36 / 49 Branchbran 46.8% 15 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 64.7% 55 / 85 CC 11 SCAR 30.7
CC
11
Cov
63%
work
27.1
BEGIN
1.0
BEGIN
1.0
CRAP 21.5
« blib/lib/WWW/Link_Controller/Lock.pm ↑ Summary blib/lib/HTML/Link_Miner.pm »
1 #!/usr/bin/perl
2  
3 =head1 Progcopy.PL
4  
5 I like to keep my perl programs in files named C<*.pl> since this
6 makes it easy to find and work with them. However it is better to
7 install them as normal programs. This does that.
8  
9 The other key thing this does is sets up the scripts to call the perl
10 interpreter correctly. I really needed this since I was working with
11 self compiled versions of perl in my home directory and not wanting to
12 disturb the main installation
13  
14 This ought to be possible through standard Makefile.PL, but I don't
15 know how.
16  
17 I also set this up to install the documentation appropriately.
18  
19 =cut
20  
21 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 $File::Find::dont_use_nlink=1; # I had problems
26  
27 1 my $perlint=$Config{"startperl"};
28 1 ▶die "can't find out how to start interpreter" unless $perlint;
Branch: 1 branch
BranchTrueFalseTotal
unless $perlint 0 1 1
29  
30 1 my $target_dir = "blib/script";
31 1 my $man_dir = "blib/man1";
32 1 ▶die "no blib to install into" unless -d "blib";
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 1 1
33 1 ▶mkdir $target_dir, 0750 unless -e $target_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $target_dir 0 1 1
34 1 ▶die "$target_dir is not a directory" unless -d $target_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $target_dir 0 1 1
35 1 $target_dir = cwd() . '/' . $target_dir . '/'; #so we can find it later
36 1 ▶mkdir $man_dir, 0750 unless -e $man_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $man_dir 0 1 1
37 1 ▶die "$man_dir is not a directory" unless -d $man_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $man_dir 0 1 1
38 1 $man_dir = cwd() . '/' . $man_dir . '/'; #so we can find it later
39  
40 171 ▶sub work {
Subroutine work: called CC=11 SCAR=33.0
41 171 ▶ -d && do { m/^((docs)|(blib)|(old)|(t))$/ and $File::Find::prune = 1;
Branch: 2 branches
BranchTrueFalseTotal
-d $_ and do { /^((docs)|(blib)|(old)|(t))$/ and $File::Find::prune = 1; return } 43 128 171
/^((docs)|(blib)|(old)|(t))$/ and $File::Find::prune = 1 4 39 43
42 43 return; };
43 128 ▶ return unless m/^[^.].*.pl$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^[^.].*.pl$/ 113 15 128
44 15 ▶ return if m/test-tmp/;
Branch: 1 branch
BranchTrueFalseTotal
if /test-tmp/ 0 15 15
45 15 my $save=$_;
46 15 ($name=$_) =~ s/.pl$//;
47 15 my $target=$target_dir . $name;
48  
49 15 ▶ if (-e $target) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $target) 15 0 15
50 15 my @origstat=stat $_;
51 15 my @targetstat=stat $target;
52 15 ▶ if ($targetstat[9] > $origstat[9]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($targetstat[9] > $origstat[9]) 15 0 15
53 15 print STDERR "$target up to date.. ignoring\n";
54 15 return;
55 }
56 }
57  
58 0 print STDERR ( "copying " . cwd() . '/' . $_
59 . " to " . $target . "\n");
60 0 ▶ open (INFILE, "<" . $_) or die "failed to open to read $_";
Branch: 1 branch
BranchTrueFalseTotal
open INFILE, '<' . $_ or die "failed to open to read $_" 0 0 0
61 0 ▶ open (OUTFILE, ">" . $target)
Branch: 1 branch
BranchTrueFalseTotal
open OUTFILE, '>' . $target or die "failed to open $target_dir$name to write" 0 0 0
62 or die "failed to open $target_dir$name to write";
63 0 $_ = <INFILE>;
64 0 ▶ s/#!\S*perl/$perlint/ or print OUTFILE $perlint, "\n";
Branch: 1 branch
BranchTrueFalseTotal
s/#!\S*perl/$perlint/ or print OUTFILE $perlint, "\n" 0 0 0
65
66 0 print OUTFILE $_;
67 0 ▶ while (<INFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INFILE)) 0 0 0
68 0 print OUTFILE $_;
69 }
70 0 close INFILE;
71 0 close OUTFILE;
72 0 chmod 0755, $target; #FIXME... what if they don't want
73 0 system "pod2man $name.pl > $man_dir$name.1";
74 0 $_=$save;
75 }
76  
77 1 find(\&work, '.' );
78  
79  
« blib/lib/WWW/Link_Controller/Lock.pm ↑ Summary blib/lib/HTML/Link_Miner.pm »