line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Valgrind::Version; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
20721
|
use strict; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
237
|
|
4
|
9
|
|
|
9
|
|
44
|
use warnings; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
395
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Test::Valgrind::Version - Object class for valgrind versions. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 1.18 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.18'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This class is used to parse, store and compare C versions. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
9
|
|
43
|
use base 'Test::Valgrind::Carp'; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
1107
|
|
25
|
|
|
|
|
|
|
|
26
|
9
|
|
|
9
|
|
51
|
use Scalar::Util (); |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
3576
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $instanceof = sub { |
29
|
|
|
|
|
|
|
Scalar::Util::blessed($_[0]) && $_[0]->isa($_[1]); |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 C |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $vg_version = Test::Valgrind::Version->new( |
37
|
|
|
|
|
|
|
command_output => qx{valgrind --version}, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $vg_version = Test::Valgrind::Version->new( |
41
|
|
|
|
|
|
|
string => '1.2.3', |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Creates a new L object representing a C version from one of these two sources : |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over 4 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if the C option is specified, then C will try to parse it as the output of C. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item * |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
otherwise the C option must be passed, and its value will be parsed as a 'dotted-integer' version number. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
An exception is raised if the version number cannot be inferred from the supplied data. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
63
|
98
|
|
|
98
|
1
|
41366
|
my ($class, %args) = @_; |
64
|
|
|
|
|
|
|
|
65
|
98
|
|
|
|
|
230
|
my $output = $args{command_output}; |
66
|
98
|
|
|
|
|
141
|
my $string; |
67
|
98
|
100
|
|
|
|
282
|
if (defined $output) { |
68
|
20
|
|
|
|
|
344
|
($string) = $output =~ /^valgrind-([0-9]+(?:\.[0-9]+)*)(?!\.)/; |
69
|
|
|
|
|
|
|
} else { |
70
|
78
|
|
|
|
|
146
|
$string = $args{string}; |
71
|
78
|
50
|
|
|
|
304
|
return $string if $string->$instanceof(__PACKAGE__); |
72
|
78
|
100
|
100
|
|
|
725
|
if (defined $string and $string =~ /^([0-9]+(?:\.[0-9]+)*)(?!\.)/) { |
73
|
71
|
|
|
|
|
198
|
$string = $1; |
74
|
|
|
|
|
|
|
} else { |
75
|
7
|
|
|
|
|
15
|
$string = undef; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
98
|
100
|
|
|
|
344
|
$class->_croak('Invalid argument') unless defined $string; |
79
|
|
|
|
|
|
|
|
80
|
86
|
|
|
|
|
736
|
my @digits = map int, split /\./, $string; |
81
|
86
|
|
|
|
|
197
|
my $last = $#digits; |
82
|
86
|
|
|
|
|
347
|
for my $i (reverse 0 .. $#digits) { |
83
|
134
|
100
|
|
|
|
441
|
last if $digits[$i]; |
84
|
48
|
|
|
|
|
101
|
--$last; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
bless { |
88
|
86
|
|
|
|
|
1199
|
_digits => [ @digits[0 .. $last] ], |
89
|
|
|
|
|
|
|
_last => $last, |
90
|
|
|
|
|
|
|
}, $class; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
BEGIN { |
94
|
9
|
|
|
9
|
|
30
|
local $@; |
95
|
9
|
|
|
84
|
|
840
|
eval "sub $_ { \$_[0]->{$_} }" for qw<_digits _last>; |
|
84
|
|
|
81
|
|
501
|
|
|
81
|
|
|
|
|
278
|
|
96
|
9
|
50
|
|
|
|
2258
|
die $@ if $@; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 OVERLOADING |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This class overloads numeric comparison operators (C<< <=> >>, C<< < >>, C<< <= >>, C< == >, C<< => >> and C<< > >>), as well as stringification. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _spaceship { |
106
|
27
|
|
|
27
|
|
232
|
my ($left, $right, $swap) = @_; |
107
|
|
|
|
|
|
|
|
108
|
27
|
100
|
|
|
|
162
|
unless ($right->$instanceof(__PACKAGE__)) { |
109
|
2
|
|
|
|
|
190
|
$right = __PACKAGE__->new(string => $right); |
110
|
|
|
|
|
|
|
} |
111
|
27
|
50
|
|
|
|
140
|
($right, $left) = ($left, $right) if $swap; |
112
|
|
|
|
|
|
|
|
113
|
27
|
|
|
|
|
1285
|
my $left_digits = $left->_digits; |
114
|
27
|
|
|
|
|
1187
|
my $right_digits = $right->_digits; |
115
|
|
|
|
|
|
|
|
116
|
27
|
|
|
|
|
916
|
my $last_cmp = $left->_last <=> $right->_last; |
117
|
27
|
100
|
|
|
|
904
|
my $last = ($last_cmp < 0) ? $left->_last : $right->_last; |
118
|
|
|
|
|
|
|
|
119
|
27
|
|
|
|
|
154
|
for my $i (0 .. $last) { |
120
|
42
|
|
|
|
|
98
|
my $cmp = $left_digits->[$i] <=> $right_digits->[$i]; |
121
|
42
|
100
|
|
|
|
341
|
return $cmp if $cmp; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
16
|
|
|
|
|
127
|
return $last_cmp; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _stringify { |
128
|
30
|
|
|
30
|
|
91
|
my $self = shift; |
129
|
30
|
|
|
|
|
50
|
my @digits = @{ $self->_digits }; |
|
30
|
|
|
|
|
1056
|
|
130
|
30
|
|
|
|
|
171
|
push @digits, 0 until @digits >= 3; |
131
|
30
|
|
|
|
|
394
|
join '.', @digits; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
use overload ( |
135
|
9
|
|
|
|
|
78
|
'<=>' => \&_spaceship, |
136
|
|
|
|
|
|
|
'""' => \&_stringify, |
137
|
|
|
|
|
|
|
fallback => 1, |
138
|
9
|
|
|
9
|
|
9213
|
); |
|
9
|
|
|
|
|
6369
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Vincent Pit, C<< >>, L. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
You can contact me by mail or on C (vincent). |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 BUGS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through the web interface at L. |
153
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SUPPORT |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
perldoc Test::Valgrind::Component |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright 2015 Vincent Pit, all rights reserved. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; # End of Test::Valgrind::Version |