blib/lib/Pandoc/Version.pm

filter: Statementstmt 100% 64 / 64 Branchbran 95.0% 19 / 20 Conditioncond 75.0% 9 / 12 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 100% 13 / 13 Podpod 85.7% 6 / 7 totaltotal 93.5% 115 / 123 SCAR 28.3
CC
17
Cov
96%
fulfills
6.0
new
6.0
cmp
4.3
CRAP 17.0
« blib/lib/App/Prove/Plugin/andoc.pm ↑ Summary blib/lib/Pandoc/Error.pm »
1 package Pandoc::Version;
2 11 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 our $VERSION = '0.9.1';
6  
7 use overload
8 11 '""' => 'string',
9 '0+' => 'number',
10 cmp => 'cmp',
11 '<=>' => 'cmp',
12 11 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Scalar::Util qw(reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Pandoc::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 our @CARP_NOT = ('Pandoc');
17  
18 sub new {
19 87 ▶ my $class = shift;
Subroutine new: called CC=6 SCAR=17.9
Pod undocumented
20  
21 # We accept array or string input
22 # (or mixed but let's not document that!)
23 my @nums =
24 map {
25 212 my $num = $_;
26 212 ▶ $num =~ /^\d+$/
Branch: 1 branch
BranchTrueFalseTotal
$num =~ /^\d+$/u or "Pandoc::Error"->throw("message", "invalid version number", "version", $num) 5 207 212
27 or Pandoc::Error->throw(
28 message => 'invalid version number',
29 version => $num
30 );
31 207 $num =~ s/^0+(?=\d)//; # ensure decimal interpretation
32 207 $num = 0 + $num;
33 207 $num
34 }
35 109 map { s/^v//i; split /\./ } ## no critic
36 89 ▶ map { 'ARRAY' CORE::eq ( reftype $_ // "" ) ? @$_ : $_ }
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq (builtin::reftype($_) // '') ? : 9 80 89
Condition100%2/2
builtin::reftype($_) // ""
l!l
1079
MC/DC100%1/1
builtin::reftype($_) // ""
builtin::reftype($_)
Truth table100%2/2
A
A= builtin::reftype($_)
Aresult
11
00
37 87 ▶ map { $_ // '' } @_;
Condition100%2/2
$_ // ""
l!l
881
MC/DC100%1/1
$_ // ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
38  
39 82 ▶ Pandoc::Error->throw('invalid version number') unless @nums;
Branch: 1 branch
BranchTrueFalseTotal
unless @nums 3 79 82
40  
41 79 return bless \@nums => $class;
42 }
43  
44 25 ▶sub string { join '.', @{ $_[0] } }
Subroutine string: called CC=1 SCAR=0.0
Pod documented
45  
46 sub number {
47 125 ▶ my ( $major, @minors ) = @{ $_[0] };
Subroutine number: called CC=2 SCAR=6.9
Pod documented
48 11 ▶ no warnings qw(uninitialized numeric);
Subroutine BEGIN: called CC=1 SCAR=0.0
49 125 ▶ if (@minors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@minors) 113 12 125
50 113 my $minor = join '', map { sprintf '%03d', $_ } @minors;
51 113 return 0 + "$major.$minor"; # return a true number
52 }
53 12 return 0 + $major;
54 }
55  
56 sub cmp {
57 my ( $a, $b ) = map {
58 55 ▶ ( blessed $_ and $_->isa('Pandoc::Version') )
Subroutine cmp: called CC=4 SCAR=14.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) && $_->isa('Pandoc::Version') ? : 55 55 110
Condition50%3/6
builtin::blessed($_) and $_->isa("Pandoc::Version")
!ll&&!rl&&r
55055
$_ // ()
l!l&&r!l&&!r
5500
MC/DC50%1/2
builtin::blessed($_) and $_->isa("Pandoc::Version")
builtin::blessed($_) $_->isa("Pandoc::Version")
MC/DC0%0/2
$_ // ()
$_ ()
Truth table66%2/3
A and B
A= builtin::blessed($_)B= $_->isa("Pandoc::Version")
ABresult
0X0
100
111
Truth table33%1/3
A // B
A= $_B= ()
ABresult
1X1
011
000
59 ? $_
60 : Pandoc::Version->new( $_ // () )
61 } ( $_[0], $_[1] );
62 55 return $a->number <=> $b->number;
63 }
64  
65 sub match {
66 7 ▶ my ( $a, $b ) = map { Pandoc::Version->new($_) } @_;
Subroutine match: called CC=3 SCAR=11.0
Pod documented
67 7 ▶ pop @$a while @$a > @$b;
Branch: 1 branch
BranchTrueFalseTotal
@$a > @$b and do { pop @$a } 7 7 14
68 7 ▶ pop @$b while @$b > @$a;
Branch: 1 branch
BranchTrueFalseTotal
@$b > @$a and do { pop @$b } 1 7 8
69  
70 7 return $a->number == $b->number;
71 }
72  
73 11 my %cmp_truth_table = (
74 '==' => [ 0, 1, 0 ],
75 '!=' => [ 1, 0, 1 ],
76 '>=' => [ 0, 1, 1 ],
77 '<=' => [ 1, 1, 0 ],
78 '<' => [ 1, 0, 0 ],
79 '>' => [ 0, 0, 1 ]
80 );
81  
82 sub fulfills {
83 17 ▶ my ( $self, $req ) = @_;
Subroutine fulfills: called CC=6 SCAR=17.9
Pod documented
84 17 ▶ return 1 unless $req;
Branch: 1 branch
BranchTrueFalseTotal
unless $req 0 17 17
85  
86 17 my @parts = split qr{\s*,\s*}, $req;
87 17 for my $part (@parts) {
88 32 my ( $op, $ver ) =
89 $part =~ m{^\s*(==|>=|>|<=|<|!=)?\s*v?(\d+(\.\d+)*)$};
90 32 ▶ if ( !defined $ver ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ver) 1 31 32
91 1 Pandoc::Error->throw(
92 message => "invalid version requirement: $req",
93 require => $req,
94 );
95 }
96  
97 31 my $cmp = $self->cmp($ver) + 1; # will be 0 for <, 1 for ==, 2 for >
98 31 ▶ return unless $cmp_truth_table{ $op || '>=' }->[$cmp];
Branch: 1 branch
BranchTrueFalseTotal
unless $cmp_truth_table{$op or ">="}[$cmp] 8 23 31
Condition100%2/2
$op || '>='
l!l
256
MC/DC100%1/1
$op || '>='
$op
Truth table100%2/2
A
A= $op
Aresult
11
00
99 }
100  
101 8 1;
102 }
103  
104 sub TO_JSON {
105 4 ▶ my ($self) = @_;
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
106 4 return [ map { 0 + $_ } @$self ];
107 }
108  
109 11 1;
110  
111 __END__
« blib/lib/App/Prove/Plugin/andoc.pm ↑ Summary blib/lib/Pandoc/Error.pm »