| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
builtin::reftype($_) // ""
MC/DC100%1/1
builtin::reftype($_) // ""
builtin::reftype($_)
Truth table100%2/2
A
A= builtin::reftype($_)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 87 | ▶ | map { $_ // '' } @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_ // ""
MC/DC100%1/1
$_ // ""
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 82 | ▶ | Pandoc::Error->throw('invalid version number') unless @nums; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
builtin::blessed($_) and $_->isa("Pandoc::Version")
$_ // ()
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")
Truth table33%1/3
A // B
A= $_B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 7 | ▶ | pop @$b while @$b > @$a; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$op || '>='
MC/DC100%1/1
$op || '>='
$op
Truth table100%2/2
A
A= $op
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||