1 package Test::Valgrind::Version;
8 Test::Valgrind::Version - Object class for valgrind versions.
16 our $VERSION = '1.17';
20 This class is used to parse, store and compare C<valgrind> versions.
24 use base 'Test::Valgrind::Carp';
28 my $instanceof = sub {
29 Scalar::Util::blessed($_[0]) && $_[0]->isa($_[1]);
36 my $vg_version = Test::Valgrind::Version->new(
37 command_output => qx{valgrind --version},
40 my $vg_version = Test::Valgrind::Version->new(
44 Creates a new L<Test::Valgrind::Version> object representing a C<valgrind> version from one of these two sources :
50 if the C<command_output> option is specified, then C<new> will try to parse it as the output of C<valgrind --version>.
54 otherwise the C<string> option must be passed, and its value will be parsed as a 'dotted-integer' version number.
58 An exception is raised if the version number cannot be inferred from the supplied data.
63 my ($class, %args) = @_;
65 my $output = $args{command_output};
67 if (defined $output) {
68 ($string) = $output =~ /^valgrind-([0-9]+(?:\.[0-9]+)*)(?!\.)/;
70 $string = $args{string};
71 return $string if $string->$instanceof(__PACKAGE__);
72 if (defined $string and $string =~ /^([0-9]+(?:\.[0-9]+)*)(?!\.)/) {
78 $class->_croak('Invalid argument') unless defined $string;
80 my @digits = map int, split /\./, $string;
82 for my $i (reverse 0 .. $#digits) {
88 _digits => [ @digits[0 .. $last] ],
95 eval "sub $_ { \$_[0]->{$_} }" for qw<_digits _last>;
101 This class overloads numeric comparison operators (C<< <=> >>, C<< < >>, C<< <= >>, C< == >, C<< => >> and C<< > >>), as well as stringification.
106 my ($left, $right, $swap) = @_;
108 unless ($right->$instanceof(__PACKAGE__)) {
109 $right = __PACKAGE__->new(string => $right);
111 ($right, $left) = ($left, $right) if $swap;
113 my $left_digits = $left->_digits;
114 my $right_digits = $right->_digits;
116 my $last_cmp = $left->_last <=> $right->_last;
117 my $last = ($last_cmp < 0) ? $left->_last : $right->_last;
119 for my $i (0 .. $last) {
120 my $cmp = $left_digits->[$i] <=> $right_digits->[$i];
129 my @digits = @{ $self->_digits };
130 push @digits, 0 until @digits >= 3;
135 '<=>' => \&_spaceship,
136 '""' => \&_stringify,
146 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
148 You can contact me by mail or on C<irc.perl.org> (vincent).
152 Please report any bugs or feature requests to C<bug-test-valgrind at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
153 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
157 You can find documentation for this module with the perldoc command.
159 perldoc Test::Valgrind::Component
161 =head1 COPYRIGHT & LICENSE
163 Copyright 2015 Vincent Pit, all rights reserved.
165 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
169 1; # End of Test::Valgrind::Version