TagVersion.pm

filter: Statementstmt 36.2% 21 / 58 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 1 totaltotal 27.2% 24 / 88 CC 11 SCAR 29.5
CC
11
Cov
27%
__ANON__
30.0
__ANON__
30.0
tag_next_version
12.0
CRAP 19.1
« TagVersion/Version.pm ↑ Summary TagVersion/App.pm »
1 package Git::TagVersion;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.00'; # VERSION
6 # ABSTRACT: module to manage version tags in git
7  
8 1 ▶use Git::TagVersion::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Git::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 1 has 'fetch' => ( is => 'rw', isa => 'Bool', default => 0 );
13 1 has 'push' => ( is => 'rw', isa => 'Bool', default => 0 );
14  
15 1 has 'root' => ( is => 'ro', isa => 'Str', default => '.' );
16 has 'repo' => (
17 is => 'ro', isa => 'Git::Wrapper', lazy => 1,
18 default => sub {
19 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 return Git::Wrapper->new( $self->root );
21 },
22 1 );
23  
24 1 has 'version_regex' => ( is => 'ro', isa => 'Str', default => '^v(\d.+)$' );
25  
26 has 'versions' => (
27 is => 'ro', isa => 'ArrayRef[Git::TagVersion::Version]', lazy => 1,
28 default => sub {
29 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
30 0 my @versions;
31  
32 0 ▶ if( $self->fetch ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fetch) 0 0 0
33 0 $self->repo->fetch;
34 }
35  
36 0 my $regex = $self->version_regex;
37 0 foreach my $tag ( $self->repo->tag ) {
38 0 ▶ if( my ($v_str) = $tag =~ /$regex/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($v_str) = $tag =~ /$regex/) 0 0 0
39 0 my $version;
40 0 eval { $version = Git::TagVersion::Version->new_from_string( $v_str ) };
41 0 ▶ if( $@ ) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
42 0 push( @versions, $version );
43 }
44 }
45 0 return [ reverse sort @versions ];
46 },
47 1 );
48  
49 has 'last_version' => (
50 is => 'ro', isa => 'Maybe[Git::TagVersion::Version]', lazy => 1,
51 default => sub {
52 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 return( $self->versions->[0] );
54 },
55 1 );
56  
57 1 has 'incr_level' => ( is => 'rw', isa => 'Int', default => 0 );
58  
59 1 has 'add_level' => ( is => 'rw', isa => 'Int', default => 0 );
60  
61 has 'next_version' => (
62 is => 'ro', isa => 'Maybe[Git::TagVersion::Version]', lazy => 1,
63 default => sub {
64 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
65 0 ▶ if( ! defined $self->last_version ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->last_version) 0 0 0
66 0 return;
67 }
68 0 ▶ if( $self->incr_level && $self->add_level ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->incr_level and $self->add_level) 0 0 0
Condition0%0/3
$self->incr_level and $self->add_level
!ll&&!rl&&r
000
MC/DC0%0/2
$self->incr_level and $self->add_level
$self->incr_level $self->add_level
Truth table0%0/3
A and B
A= $self->incr_levelB= $self->add_level
ABresult
0X0
100
111
69 0 die('use increment or new minor version, not both');
70 }
71 0 my $next = $self->last_version->clone;
72 0 ▶ if( $self->add_level ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->add_level) { } 0 0 0
73 0 $next->add_level( $self->add_level );
74 } else {
75 0 $next->increment( $self->incr_level );
76 }
77 0 return $next;
78 },
79 1 );
80  
81 sub tag_next_version {
82 0 ▶ my $self = shift;
Subroutine tag_next_version: not called CC=3 SCAR=24.8
Pod undocumented
83 0 my $next = $self->next_version;
84  
85 0 ▶ if( ! defined $next ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $next) 0 0 0
86 0 die('next version is not defined');
87 }
88  
89 0 my $tag = 'v'.$next->as_string;
90 0 $self->repo->tag($tag);
91  
92 0 ▶ if( $self->push ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->push) 0 0 0
93 0 $self->repo->push('origin', $tag);
94 }
95  
96 0 return $tag;
97 }
98  
99 1 1;
100  
101 __END__
102  
103 =pod
104  
105 =encoding UTF-8
106  
107 =head1 NAME
108  
109 Git::TagVersion - module to manage version tags in git
110  
111 =head1 VERSION
112  
113 version 1.00
114  
115 =head1 AUTHOR
116  
117 Markus Benning <ich@markusbenning.de>
118  
119 =head1 COPYRIGHT AND LICENSE
120  
121 This software is copyright (c) 2015 by Markus Benning <me@w3r3wolf.de>.
122  
123 This is free software; you can redistribute it and/or modify it under
124 the same terms as the Perl 5 programming language system itself.
125  
126 =cut
« TagVersion/Version.pm ↑ Summary TagVersion/App.pm »