| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | 0 | my $version; | |||||||||||||||||||||||||||
| 40 | 0 | eval { $version = Git::TagVersion::Version->new_from_string( $v_str ) }; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | if( $@ ) { next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if( $self->incr_level && $self->add_level ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->incr_level and $self->add_level
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||