| 1 | package Git::TagVersion::Version; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '1.00'; # VERSION | |||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: class for working with a version number | ||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | use overload | ||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | 'cmp' => \&_cmp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | has 'digits' => ( | ||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | is => 'rw', isa => 'ArrayRef[Int]', default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ); | |||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | has 'seperator' => ( is => 'ro', isa => 'Str', default => '.' ); | |||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||
| 17 | sub _cmp { | ||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my ( $obj_a, $obj_b ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmp: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | while( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $obj_a->digits->[$i] and defined $obj_b->digits->[$i]
MC/DC0%0/2
defined $obj_a->digits->[$i] and defined $obj_b->digits->[$i]
defined $obj_a->digits->[$i]
defined $obj_b->digits->[$i]
Truth table0%0/3
A and B
A= defined $obj_a->digits->[$i]B= defined $obj_b->digits->[$i]
| |||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if( defined $a && ! defined $b ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
defined $a and not defined $b
MC/DC0%0/2
defined $a and not defined $b
defined $a
not defined $b
Truth table0%0/3
A and not(B)
A= defined $aB= not defined $b
| |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 28 | ▶ | } elsif( ! defined ! $a && defined $b ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not defined !$a and defined $b
MC/DC0%0/2
not defined !$a and defined $b
not defined !$a
defined $b
Truth table0%0/3
A and B
A= not defined !$aB= 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return __PACKAGE__->new( digits => [ @{$self->digits} ] ); | |||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | sub increment { | ||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my ( $self, $level ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
increment: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $i = -1 - $level; | |||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my @digits = @{$self->digits}; | |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $value = $digits[$i]; | |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if( ! defined $value ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ( $self, $level ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_level: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my @digits = @{$self->digits}; | |||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return( join( $self->seperator, @{$self->digits} ) ); | |||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||
| 78 | sub parse_string { | ||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my ( $self, $string ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $string =~ s/^v//; | |||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my @digits = split(/\./, $string ); | |||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | foreach my $d ( @digits ) { | |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( $d !~ /^\d+$/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ( $class, $string ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $obj = $class->new; | |||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $obj->parse_string( $string ); | |||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return $obj; | |||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | 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 | ||||||||||||||||||||||||||||||||||||||||