line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::TagVersion::Version; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.00'; # VERSION |
6
|
|
|
|
|
|
|
# ABSTRACT: class for working with a version number |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use overload |
9
|
1
|
|
|
1
|
|
6404
|
'cmp' => \&_cmp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'digits' => ( |
12
|
|
|
|
|
|
|
is => 'rw', isa => 'ArrayRef[Int]', default => sub { [] }, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'seperator' => ( is => 'ro', isa => 'Str', default => '.' ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _cmp { |
18
|
0
|
|
|
0
|
|
|
my ( $obj_a, $obj_b ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $i = 0; |
21
|
0
|
|
0
|
|
|
|
while( |
22
|
|
|
|
|
|
|
defined $obj_a->digits->[$i] |
23
|
|
|
|
|
|
|
&& defined $obj_b->digits->[$i] ) { |
24
|
0
|
|
|
|
|
|
my $a = $obj_a->digits->[$i]; |
25
|
0
|
|
|
|
|
|
my $b = $obj_b->digits->[$i]; |
26
|
0
|
0
|
0
|
|
|
|
if( defined $a && ! defined $b ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return 1; |
28
|
|
|
|
|
|
|
} elsif( ! defined ! $a && defined $b ) { |
29
|
0
|
|
|
|
|
|
return -1; |
30
|
|
|
|
|
|
|
} elsif( $a > $b ) { |
31
|
0
|
|
|
|
|
|
return 1; |
32
|
|
|
|
|
|
|
} elsif( $a < $b ) { |
33
|
0
|
|
|
|
|
|
return -1; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
|
$i++ |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub clone { |
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
return __PACKAGE__->new( digits => [ @{$self->digits} ] ); |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub increment { |
47
|
0
|
|
|
0
|
0
|
|
my ( $self, $level ) = @_; |
48
|
0
|
|
|
|
|
|
my $i = -1 - $level; |
49
|
0
|
|
|
|
|
|
my @digits = @{$self->digits}; |
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $value = $digits[$i]; |
52
|
0
|
0
|
|
|
|
|
if( ! defined $value ) { |
53
|
0
|
|
|
|
|
|
die("cannot increment version at level $level"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$value++; |
57
|
0
|
|
|
|
|
|
splice @digits, $i, ($level + 1), ( $value, (0) x $level ) ; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->digits( \@digits ); |
60
|
0
|
|
|
|
|
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_level { |
64
|
0
|
|
|
0
|
0
|
|
my ( $self, $level ) = @_; |
65
|
0
|
|
|
|
|
|
my @digits = @{$self->digits}; |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
foreach my $i (1..$level) { |
67
|
0
|
|
|
|
|
|
push( @digits, 0 ); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
$self->digits( \@digits ); |
70
|
0
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub as_string { |
74
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
return( join( $self->seperator, @{$self->digits} ) ); |
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub parse_string { |
79
|
0
|
|
|
0
|
0
|
|
my ( $self, $string ) = @_; |
80
|
0
|
|
|
|
|
|
$string =~ s/^v//; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my @digits = split(/\./, $string ); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
foreach my $d ( @digits ) { |
85
|
0
|
0
|
|
|
|
|
if( $d !~ /^\d+$/ ) { |
86
|
0
|
|
|
|
|
|
die("$d is not numeric in version string"); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->digits( \@digits ); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub new_from_string { |
96
|
0
|
|
|
0
|
0
|
|
my ( $class, $string ) = @_; |
97
|
0
|
|
|
|
|
|
my $obj = $class->new; |
98
|
0
|
|
|
|
|
|
$obj->parse_string( $string ); |
99
|
0
|
|
|
|
|
|
return $obj; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding UTF-8 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Git::TagVersion::Version - class for working with a version number |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
version 1.00 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Markus Benning <me@w3r3wolf.de>. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |