RackTables.pm

filter: Statementstmt 93.6% 59 / 63 Branchbran 55.5% 10 / 18 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 11 / 11 Podpod 50.0% 1 / 2 totaltotal 86.6% 84 / 97 CC 10 SCAR 18.9
CC
10
Cov
86%
BUILDARGS
12.2
BEGIN
1.0
BEGIN
1.0
CRAP 6.6
↑ Summary RackTables/0_14_10.pm »
1 package Schema::RackTables;
2  
3 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 3 our $VERSION = "1.01";
15  
16 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 REF_DB_PATH => catfile(dirname($INC{"Schema/RackTables.pm"}),
18 "RackTables", "versions.json")
19 3 };
20  
21  
22 3 has version => ( is => "ro" );
23 3 has schema => ( is => "ro" );
24 3 has schema_version => ( is => "ro" );
25  
26  
27 3 my $ref_db = decode_json(do {
28 3 ▶ open my $fh, "<", REF_DB_PATH or die "Can't read '", REF_DB_PATH, "': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "/home/cpancover/.cpan/build/Schema-RackTables-1.01-0/blib/lib/Schema/RackTables/versions.json" or die "Can't read '", "/home/cpancover/.cpan/build/Schema-RackTables-1.01-0/blib/lib/Schema/RackTables/versions.json", "': $!\n" 3 0 3
29 3 local $/; <$fh>
30 3 });
31  
32 3 my %schema_for = map { $_->{version} => $_->{schema} } @{$ref_db->{versions}};
33  
34  
35 #
36 # list_versions
37 # -------------
38 1 ▶sub list_versions {
Subroutine list_versions: called CC=1 SCAR=0.0
Pod documented
39 1 return map { $_->{version} } @{$ref_db->{versions}}
40 }
41  
42  
43 #
44 # BUILDARGS
45 # ---------
46 8 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=10 SCAR=25.1
Pod undocumented
47 8 my ($class, @args) = @_;
48 8 my %param;
49  
50 8 ▶ if (@args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1) { } 0 8 8
51 0 ▶ croak "Single parameters to new() must be a hash reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args[0] eq "HASH" 0 0 0
52 unless ref $args[0] eq "HASH";
53 0 %param = %{$args[0]};
54 }
55 else {
56 8 ▶ croak "The new() method expects a hash reference or a key/value list"
Branch: 1 branch
BranchTrueFalseTotal
unless @args % 2 == 0 0 8 8
57 unless @args % 2 == 0;
58 8 %param = @args;
59 }
60  
61 # default to latest version if none requested
62 8 ▶ $param{version} //= "latest";
Condition100%2/2
$param{"version"} //= "latest"
l!l
71
MC/DC100%1/1
$param{"version"} //= "latest"
$param{"version"}
Truth table100%2/2
A
A= $param{"version"}
Aresult
11
00
63 $param{version} = $ref_db->{versions}[-1]{version}
64 8 ▶ if $param{version} eq "latest";
Branch: 1 branch
BranchTrueFalseTotal
if $param{"version"} eq "latest" 2 6 8
65  
66 # validate input version; RackTables only has x.y.z for now
67 8 ▶ if ($param{version} =~ /^([0-9]+\.[0-9]+\.[0-9]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{'version'} =~ /^([0-9]+\.[0-9]+\.[0-9]+)$/) { } 5 3 8
68 5 $param{version} = $1;
69 }
70 else {
71 3 croak "invalid version '$param{version}'";
72 }
73  
74 # find the schema version corresponding to the request software version
75 $param{schema_version} = $schema_for{ $param{version} }
76 5 ▶ or croak "invalid version '$param{version}'";
Branch: 1 branch
BranchTrueFalseTotal
$param{"schema_version"} = $schema_for{$param{"version"}} or croak(qq[invalid version '$param{"version"}']) 5 0 5
77  
78 # load the corresponding schema and instanciate it
79 5 ▶ if ($param{schema_version} =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{'schema_version'} =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/) { } 5 0 5
80 # convoluted way to fetch the version so that $module isn't tainted
81 5 my $vn = "$1\_$2\_$3";
82 5 my $module = "$class\::$vn";
83 5 ▶ eval "require $module" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $module" or die $@ 5 0 5
84 5 $param{schema} = $module;
85 }
86 else {
87 0 die "invalid schema version '$param{schema_version}'\n"
88 }
89  
90 5 return \%param
91 }
92  
93  
94 3 __PACKAGE__
95  
96 __END__
↑ Summary RackTables/0_14_10.pm »