line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::TagVersion::Version; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.01'; # VERSION |
6
|
|
|
|
|
|
|
# ABSTRACT: class for working with a version number |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
12307
|
use Template; |
|
1
|
|
|
|
|
26239
|
|
|
1
|
|
|
|
|
38
|
|
9
|
1
|
|
|
1
|
|
917
|
use File::Slurp; |
|
1
|
|
|
|
|
14185
|
|
|
1
|
|
|
|
|
81
|
|
10
|
1
|
|
|
1
|
|
13973
|
use Time::Piece; |
|
1
|
|
|
|
|
31478
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use overload |
13
|
1
|
|
|
1
|
|
131
|
'cmp' => \&_cmp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'digits' => ( |
16
|
|
|
|
|
|
|
is => 'rw', isa => 'ArrayRef[Int]', default => sub { [] }, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'seperator' => ( is => 'ro', isa => 'Str', default => '.' ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'tag' => ( is => 'rw', isa => 'Maybe[Str]' ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'prev' => ( is => 'rw', isa => 'Maybe[Git::TagVersion::Version]' ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'repo' => ( is => 'ro', isa => 'Git::Wrapper', required => 1 ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'log' => ( |
28
|
|
|
|
|
|
|
is => 'ro', isa => 'ArrayRef[Git::Wrapper::Log]', lazy => 1, |
29
|
|
|
|
|
|
|
default => sub { |
30
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
my @log; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $revisions; |
34
|
|
|
|
|
|
|
if( defined $self->prev ) { |
35
|
|
|
|
|
|
|
$revisions = $self->prev->tag.'...'.$self->tag; |
36
|
|
|
|
|
|
|
} else { |
37
|
|
|
|
|
|
|
$revisions = $self->tag; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
@log = $self->repo->log( $revisions ); |
41
|
|
|
|
|
|
|
return \@log; |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'date' => ( |
46
|
|
|
|
|
|
|
is => 'ro', isa => 'Maybe[Time::Piece]', lazy => 1, |
47
|
|
|
|
|
|
|
default => sub { |
48
|
|
|
|
|
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
if( defined $self->log->[0] ) { |
50
|
|
|
|
|
|
|
my $date = $self->log->[0]->date; |
51
|
|
|
|
|
|
|
$date =~ s/^\w+ //; |
52
|
|
|
|
|
|
|
return Time::Piece->strptime( |
53
|
|
|
|
|
|
|
$date, |
54
|
|
|
|
|
|
|
"%b %d %H:%M:%S %Y %z", |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
has 'author' => ( |
61
|
|
|
|
|
|
|
is => 'ro', isa => 'Maybe[Str]', lazy => 1, |
62
|
|
|
|
|
|
|
default => sub { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
if( defined $self->log->[0] ) { |
65
|
|
|
|
|
|
|
return( $self->log->[0]->author ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
return; |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _cmp { |
72
|
0
|
|
|
0
|
|
|
my ( $obj_a, $obj_b ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $i = 0; |
75
|
0
|
|
0
|
|
|
|
while( |
76
|
|
|
|
|
|
|
defined $obj_a->digits->[$i] |
77
|
|
|
|
|
|
|
&& defined $obj_b->digits->[$i] ) { |
78
|
0
|
|
|
|
|
|
my $a = $obj_a->digits->[$i]; |
79
|
0
|
|
|
|
|
|
my $b = $obj_b->digits->[$i]; |
80
|
0
|
0
|
0
|
|
|
|
if( defined $a && ! defined $b ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return 1; |
82
|
|
|
|
|
|
|
} elsif( ! defined ! $a && defined $b ) { |
83
|
0
|
|
|
|
|
|
return -1; |
84
|
|
|
|
|
|
|
} elsif( $a > $b ) { |
85
|
0
|
|
|
|
|
|
return 1; |
86
|
|
|
|
|
|
|
} elsif( $a < $b ) { |
87
|
0
|
|
|
|
|
|
return -1; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
$i++ |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub clone { |
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
return __PACKAGE__->new( |
98
|
0
|
|
|
|
|
|
digits => [ @{$self->digits} ], |
|
0
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
repo => $self->repo, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub increment { |
104
|
0
|
|
|
0
|
0
|
|
my ( $self, $level ) = @_; |
105
|
0
|
|
|
|
|
|
my $i = -1 - $level; |
106
|
0
|
|
|
|
|
|
my @digits = @{$self->digits}; |
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $value = $digits[$i]; |
109
|
0
|
0
|
|
|
|
|
if( ! defined $value ) { |
110
|
0
|
|
|
|
|
|
die("cannot increment version at level $level"); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$value++; |
114
|
0
|
|
|
|
|
|
splice @digits, $i, ($level + 1), ( $value, (0) x $level ) ; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$self->digits( \@digits ); |
117
|
0
|
|
|
|
|
|
return; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub add_level { |
121
|
0
|
|
|
0
|
0
|
|
my ( $self, $level ) = @_; |
122
|
0
|
|
|
|
|
|
my @digits = @{$self->digits}; |
|
0
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
foreach my $i (1..$level) { |
124
|
0
|
|
|
|
|
|
push( @digits, 0 ); |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
|
$self->digits( \@digits ); |
127
|
0
|
|
|
|
|
|
return; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub as_string { |
131
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
132
|
0
|
|
|
|
|
|
return( join( $self->seperator, @{$self->digits} ) ); |
|
0
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub parse_version { |
136
|
0
|
|
|
0
|
0
|
|
my ( $self, $version ) = @_; |
137
|
0
|
|
|
|
|
|
$version =~ s/^v//; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my @digits = split(/\./, $version ); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
foreach my $d ( @digits ) { |
142
|
0
|
0
|
|
|
|
|
if( $d !~ /^\d+$/ ) { |
143
|
0
|
|
|
|
|
|
die("$d is not numeric in version tag"); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$self->digits( \@digits ); |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
has '_tt' => ( |
153
|
|
|
|
|
|
|
is => 'ro', isa => 'Template', lazy => 1, |
154
|
|
|
|
|
|
|
default => sub { |
155
|
|
|
|
|
|
|
return Template->new( |
156
|
|
|
|
|
|
|
EVAL_PERL => 1, |
157
|
|
|
|
|
|
|
); |
158
|
|
|
|
|
|
|
}, |
159
|
|
|
|
|
|
|
); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
has 'template_file' => ( is => 'ro', isa => 'Maybe[Str]' ); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
has '_template' => ( |
164
|
|
|
|
|
|
|
is => 'ro', isa => 'Str', lazy => 1, |
165
|
|
|
|
|
|
|
default => sub { |
166
|
|
|
|
|
|
|
my $self = shift; |
167
|
|
|
|
|
|
|
if( $self->template_file ) { |
168
|
|
|
|
|
|
|
return read_file( $self->template_file ); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
return read_file( \*DATA ); |
171
|
|
|
|
|
|
|
}, |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub render { |
175
|
0
|
|
|
0
|
0
|
|
my ( $self, $style ) = @_; |
176
|
0
|
0
|
|
|
|
|
if( ! defined $style ) { |
177
|
0
|
|
|
|
|
|
$style = 'simple'; |
178
|
|
|
|
|
|
|
} |
179
|
0
|
|
|
|
|
|
my $template = $self->_template; |
180
|
0
|
|
|
|
|
|
my $out; |
181
|
|
|
|
|
|
|
|
182
|
0
|
0
|
|
|
|
|
$self->_tt->process( \$template, { |
183
|
|
|
|
|
|
|
style => $style, |
184
|
|
|
|
|
|
|
self => $self, |
185
|
|
|
|
|
|
|
}, \$out ) |
186
|
|
|
|
|
|
|
or die $self->_tt->error()."\n"; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
return $out; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=pod |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=encoding UTF-8 |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 NAME |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Git::TagVersion::Version - class for working with a version number |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 VERSION |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
version 1.01 |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 AUTHOR |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Markus Benning <ich@markusbenning.de>. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
214
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
__DATA__ |
219
|
|
|
|
|
|
|
[% BLOCK markdown -%] |
220
|
|
|
|
|
|
|
## Release [[% self.as_string %]] - [% self.date.strftime("%Y-%m-%d") %] |
221
|
|
|
|
|
|
|
[% FOREACH log = self.log -%] |
222
|
|
|
|
|
|
|
- [% log.message.match('^(.*)\n').0 %] |
223
|
|
|
|
|
|
|
[% END -%] |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
[% END -%] |
226
|
|
|
|
|
|
|
[% BLOCK rpm -%] |
227
|
|
|
|
|
|
|
* [% self.date.strftime("%a %b %d %Y") %] [% self.author %] [% self.as_string %] |
228
|
|
|
|
|
|
|
[% FOREACH log = self.log -%] |
229
|
|
|
|
|
|
|
- [% log.message.match('^(.*)\n').0 %] |
230
|
|
|
|
|
|
|
[% END -%] |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
[% END -%] |
233
|
|
|
|
|
|
|
[% BLOCK simple -%] |
234
|
|
|
|
|
|
|
Changes in version [% self.as_string %]: |
235
|
|
|
|
|
|
|
[% FOREACH log = self.log -%] |
236
|
|
|
|
|
|
|
* [% log.message.match('^(.*)\n').0 %] |
237
|
|
|
|
|
|
|
[% END -%] |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
[% END -%] |
240
|
|
|
|
|
|
|
[% INCLUDE $style -%] |