blib/lib/only/latest.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 76.6% 23 / 30 Conditioncond 75.0% 9 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 84.0% 84 / 100 CC 21 SCAR 23.7
CC
21
Cov
86%
__ANON__
12.9
parse_version
10.0
import
1.0
CRAP 10.7
↑ Summary
1 # $File: //member/autrijus/only-latest/lib/only/latest.pm $ $Author: autrijus $
2 # $Revision: #1 $ $Change: 8676 $ $only: 2003/11/01 06:14:05 $
3  
4 package only::latest;
5 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 $only::latest::VERSION = '0.01';
8  
9 =head1 NAME
10  
11 only::latest - Always use the latest version of a module in @INC
12  
13 =head1 VERSION
14  
15 This document describes version 0.01 of only::latest, released
16 November 4, 2003.
17  
18 =head1 SYNOPSIS
19  
20 use lib "/some/dir";
21 use only::latest;
22 use DBI; # use "/some/dir/DBI.pm" only if it's newer than system's
23  
24 =head1 DESCRIPTION
25  
26 This module is for people with separately-maintained INC directories
27 containing overlapping modules, who wishes to always use the latest version
28 of a module, regardless of the directory it is in.
29  
30 If you C<use> or C<require> a module living in more than one directory,
31 the one with the highest C<$VERSION> is preferred, and its directory will
32 be tried first during the next time. If there is a tie, the first-tried one
33 is used.
34  
35 The implementation puts a hook in front of C<@INC>; this means it should
36 come after all C<use lib> statements.
37  
38 If you wish to limit this module to some specific targets, list them as
39 the import arguments, like this:
40  
41 use only::latest qw(CGI CGI::Fast);
42 use DBI; # not affected
43  
44 =cut
45  
46 1 ▶sub import {
Subroutine import: called CC=1 SCAR=0.1
47 1 my ($class, @pkgs) = @_;
48 0 my %intercept = map { s{::}{/}g; "$_.pm" => 1 } @pkgs;
49 1 my $cur_prefix;
50  
51 22 ▶ unshift @INC, sub {
Subroutine __ANON__: called CC=12 SCAR=25.6
52 22 my ($self, $file) = @_;
53 22 ▶ return undef if %intercept and !$intercept{$file};
Branch: 1 branch
BranchTrueFalseTotal
if %intercept and not $intercept{$file} 0 22 22
Condition33%1/3
%intercept and not $intercept{$file}
!ll&&!rl&&r
2200
MC/DC0%0/2
%intercept and not $intercept{$file}
%intercept not $intercept{$file}
Truth table33%1/3
A and not(B)
A= %interceptB= not $intercept{$file}
ABresult
0X0
100
111
54  
55 22 my ($cur_ver, $cur_file) = (-1, undef);
56 22 foreach my $prefix ($cur_prefix, grep { $_ ne $cur_prefix } @INC) {
57 240 ▶ next if !defined($prefix) or ref($prefix);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $prefix or ref $prefix 44 196 240
Condition100%3/3
not defined $prefix or ref $prefix
l!l&&r!l&&!r
2222196
MC/DC100%2/2
not defined $prefix or ref $prefix
not defined $prefix ref $prefix
Truth table100%3/3
not(A) or B
A= not defined $prefixB= ref $prefix
ABresult
1X1
011
000
58 196 my $pathname = "$prefix/$file";
59 196 ▶ next unless -e $pathname and !-d $pathname;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $pathname and not -d $pathname 176 20 196
Condition66%2/3
-e $pathname and not -d $pathname
!ll&&!rl&&r
176020
MC/DC50%1/2
-e $pathname and not -d $pathname
-e $pathname not -d $pathname
Truth table66%2/3
A and not(B)
A= -e $pathnameB= not -d $pathname
ABresult
0X0
100
111
60 20 my $ver = $class->parse_version($pathname);
61 20 ▶ next unless $ver > $cur_ver;
Branch: 1 branch
BranchTrueFalseTotal
unless $ver > $cur_ver 0 20 20
62 20 ▶ $cur_prefix = $prefix if $cur_file; # if it wins, remember it
Branch: 1 branch
BranchTrueFalseTotal
if $cur_file 0 20 20
63 20 ($cur_ver, $cur_file) = ($ver, $pathname);
64 }
65  
66 22 ▶ return undef unless $cur_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $cur_file 2 20 22
67 20 ▶ open my($fh), $cur_file or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $cur_file or return undef 20 0 20
68 20 return $fh;
69 }
70 1 }
71  
72 # Copied verbatim from ExtUtils::MM_Unix
73 20 ▶sub parse_version {
Subroutine parse_version: called CC=10 SCAR=23.1
Pod undocumented
74 20 my($self,$parsefile) = @_;
75 20 my $result;
76 20 local *FH;
77 20 local $/ = "\n";
78 20 local $_;
79 20 ▶ open(FH,$parsefile) or die "Could not open '$parsefile': $!";
Branch: 1 branch
BranchTrueFalseTotal
open FH, $parsefile or die "Could not open '${parsefile}': $!" 20 0 20
80 20 my $inpod = 0;
81 20 ▶ while (<FH>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FH)) 277 1 278
82 277 ▶ $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
Branch: 2 branches
BranchTrueFalseTotal
/^=(?!cut)/ ? : 6 271 277
/^=cut/ ? : 0 271 271
83 277 ▶ next if $inpod || /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $inpod or /^\s*#/ 117 160 277
Condition100%3/3
$inpod or /^\s*#/
l!l&&r!l&&!r
9126160
MC/DC100%2/2
$inpod or /^\s*#/
$inpod /^\s*#/
Truth table100%3/3
A or B
A= $inpodB= /^\s*#/
ABresult
1X1
011
000
84 160 chop;
85 160 ▶ next unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
Branch: 1 branch
BranchTrueFalseTotal
unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ 141 19 160
86 19 my $eval = qq{
87 package ExtUtils::MakeMaker::_version;
88  
89 local $1$2;
90 \$$2=undef; do {
91 $_
92 }; \$$2
93 };
94 19 local $^W = 0;
95 19 $result = eval($eval);
96 19 ▶ warn "Could not eval '$eval' in $parsefile: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 19 19
97 19 last;
98 }
99 20 close FH;
100  
101 20 ▶ $result = "undef" unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 1 19 20
102 20 return $result;
103 }
104  
105 1 1;
106  
107 =head1 AUTHORS
108  
109 Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>
110  
111 Part of code derived from L<ExtUtils::MM_Unix>.
112  
113 =head1 COPYRIGHT
114  
115 Copyright 2003 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.
116  
117 This program is free software; you can redistribute it and/or
118 modify it under the same terms as Perl itself.
119  
120 See L<http://www.perl.com/perl/misc/Artistic.html>
121  
122 =cut
↑ Summary