Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/CPAN/Version.pm |
Statements | Executed 22 statements in 331µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 217µs | 290µs | vcmp | CPAN::Version::
5 | 3 | 1 | 58µs | 58µs | CORE:match (opcode) | CPAN::Version::
1 | 1 | 1 | 41µs | 331µs | vge | CPAN::Version::
2 | 1 | 1 | 15µs | 15µs | CORE:subst (opcode) | CPAN::Version::
0 | 0 | 0 | 0s | 0s | BEGIN | CPAN::Version::
0 | 0 | 0 | 0s | 0s | float2vv | CPAN::Version::
0 | 0 | 0 | 0s | 0s | readable | CPAN::Version::
0 | 0 | 0 | 0s | 0s | vgt | CPAN::Version::
0 | 0 | 0 | 0s | 0s | vle | CPAN::Version::
0 | 0 | 0 | 0s | 0s | vlt | CPAN::Version::
0 | 0 | 0 | 0s | 0s | vstring | CPAN::Version::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package CPAN::Version; | ||||
2 | |||||
3 | use strict; | ||||
4 | use vars qw($VERSION); | ||||
5 | $VERSION = "5.5003"; | ||||
6 | |||||
7 | # CPAN::Version::vcmp courtesy Jost Krieger | ||||
8 | # spent 290µs (217+73) within CPAN::Version::vcmp which was called:
# once (217µs+73µs) by CPAN::Version::vge at line 69 | ||||
9 | 1 | 26µs | my($self,$l,$r) = @_; | ||
10 | 1 | 17µs | local($^W) = 0; | ||
11 | 1 | 1µs | CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG; | ||
12 | |||||
13 | # treat undef as zero | ||||
14 | 1 | 21µs | $l = 0 if $l eq 'undef'; | ||
15 | 1 | 0s | $r = 0 if $r eq 'undef'; | ||
16 | |||||
17 | 1 | 15µs | return 0 if $l eq $r; # short circuit for quicker success | ||
18 | |||||
19 | 1 | 1µs | for ($l,$r) { | ||
20 | 2 | 32µs | 2 | 15µs | s/_//g; # spent 15µs making 2 calls to CPAN::Version::CORE:subst, avg 8µs/call |
21 | } | ||||
22 | 1 | 14µs | CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG; | ||
23 | 1 | 14µs | for ($l,$r) { | ||
24 | 2 | 30µs | 2 | 16µs | next unless tr/.// > 1 || /^v/; # spent 16µs making 2 calls to CPAN::Version::CORE:match, avg 8µs/call |
25 | s/^v?/v/; | ||||
26 | 1 while s/\.0+(\d)/.$1/; # remove leading zeroes per group | ||||
27 | } | ||||
28 | 1 | 1µs | CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG; | ||
29 | 1 | 55µs | 2 | 33µs | if ($l=~/^v/ <=> $r=~/^v/) { # spent 33µs making 2 calls to CPAN::Version::CORE:match, avg 16µs/call |
30 | for ($l,$r) { | ||||
31 | next if /^v/; | ||||
32 | $_ = $self->float2vv($_); | ||||
33 | } | ||||
34 | } | ||||
35 | 1 | 0s | CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG; | ||
36 | 1 | 4µs | my $lvstring = "v0"; | ||
37 | 1 | 1µs | my $rvstring = "v0"; | ||
38 | 1 | 27µs | 1 | 9µs | if ($] >= 5.006 # spent 9µs making 1 call to CPAN::Version::CORE:match |
39 | && $l =~ /^v/ | ||||
40 | && $r =~ /^v/) { | ||||
41 | $lvstring = $self->vstring($l); | ||||
42 | $rvstring = $self->vstring($r); | ||||
43 | CPAN->debug(sprintf "lv[%vd] rv[%vd]", $lvstring, $rvstring) if $CPAN::DEBUG; | ||||
44 | } | ||||
45 | |||||
46 | return ( | ||||
47 | 1 | 20µs | ($l ne "undef") <=> ($r ne "undef") | ||
48 | || | ||||
49 | $lvstring cmp $rvstring | ||||
50 | || | ||||
51 | $l <=> $r | ||||
52 | || | ||||
53 | $l cmp $r | ||||
54 | ); | ||||
55 | } | ||||
56 | |||||
57 | sub vgt { | ||||
58 | my($self,$l,$r) = @_; | ||||
59 | $self->vcmp($l,$r) > 0; | ||||
60 | } | ||||
61 | |||||
62 | sub vlt { | ||||
63 | my($self,$l,$r) = @_; | ||||
64 | $self->vcmp($l,$r) < 0; | ||||
65 | } | ||||
66 | |||||
67 | # spent 331µs (41+290) within CPAN::Version::vge which was called:
# once (41µs+290µs) by CPAN::__ANON__[/usr/local/perls/perl-5.26.1/lib/5.26.1/CPAN.pm:1113] at line 1104 of CPAN.pm | ||||
68 | 1 | 3µs | my($self,$l,$r) = @_; | ||
69 | 1 | 49µs | 1 | 290µs | $self->vcmp($l,$r) >= 0; # spent 290µs making 1 call to CPAN::Version::vcmp |
70 | } | ||||
71 | |||||
72 | sub vle { | ||||
73 | my($self,$l,$r) = @_; | ||||
74 | $self->vcmp($l,$r) <= 0; | ||||
75 | } | ||||
76 | |||||
77 | sub vstring { | ||||
78 | my($self,$n) = @_; | ||||
79 | $n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]"; | ||||
80 | pack "U*", split /\./, $n; | ||||
81 | } | ||||
82 | |||||
83 | # vv => visible vstring | ||||
84 | sub float2vv { | ||||
85 | my($self,$n) = @_; | ||||
86 | my($rev) = int($n); | ||||
87 | $rev ||= 0; | ||||
88 | my($mantissa) = $n =~ /\.(\d{1,12})/; # limit to 12 digits to limit | ||||
89 | # architecture influence | ||||
90 | $mantissa ||= 0; | ||||
91 | $mantissa .= "0" while length($mantissa)%3; | ||||
92 | my $ret = "v" . $rev; | ||||
93 | while ($mantissa) { | ||||
94 | $mantissa =~ s/(\d{1,3})// or | ||||
95 | die "Panic: length>0 but not a digit? mantissa[$mantissa]"; | ||||
96 | $ret .= ".".int($1); | ||||
97 | } | ||||
98 | # warn "n[$n]ret[$ret]"; | ||||
99 | $ret =~ s/(\.0)+/.0/; # v1.0.0 => v1.0 | ||||
100 | $ret; | ||||
101 | } | ||||
102 | |||||
103 | sub readable { | ||||
104 | my($self,$n) = @_; | ||||
105 | $n =~ /^([\w\-\+\.]+)/; | ||||
106 | |||||
107 | return $1 if defined $1 && length($1)>0; | ||||
108 | # if the first user reaches version v43, he will be treated as "+". | ||||
109 | # We'll have to decide about a new rule here then, depending on what | ||||
110 | # will be the prevailing versioning behavior then. | ||||
111 | |||||
112 | if ($] < 5.006) { # or whenever v-strings were introduced | ||||
113 | # we get them wrong anyway, whatever we do, because 5.005 will | ||||
114 | # have already interpreted 0.2.4 to be "0.24". So even if he | ||||
115 | # indexer sends us something like "v0.2.4" we compare wrongly. | ||||
116 | |||||
117 | # And if they say v1.2, then the old perl takes it as "v12" | ||||
118 | |||||
119 | if (defined $CPAN::Frontend) { | ||||
120 | $CPAN::Frontend->mywarn("Suspicious version string seen [$n]\n"); | ||||
121 | } else { | ||||
122 | warn("Suspicious version string seen [$n]\n"); | ||||
123 | } | ||||
124 | return $n; | ||||
125 | } | ||||
126 | my $better = sprintf "v%vd", $n; | ||||
127 | CPAN->debug("n[$n] better[$better]") if $CPAN::DEBUG; | ||||
128 | return $better; | ||||
129 | } | ||||
130 | |||||
131 | 1; | ||||
132 | |||||
133 | __END__ | ||||
sub CPAN::Version::CORE:match; # opcode | |||||
# spent 15µs within CPAN::Version::CORE:subst which was called 2 times, avg 8µs/call:
# 2 times (15µs+0s) by CPAN::Version::vcmp at line 20, avg 8µs/call |