blib/lib/Schema/Abstract.pm

filter: Statementstmt 43.4% 20 / 46 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod 100% 4 / 4 totaltotal 44.7% 30 / 67 CC 4 SCAR 19.0
CC
4
Cov
38%
new
20.0
list_versions
2.0
schema
2.0
CRAP 6.7
↑ Summary
1 package Schema::Abstract;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Perl6::Slurp qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 our $VERSION = 0.02;
12  
13 # Constructor.
14 sub new {
15 0 ▶ my ($class, @params) = @_;
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
16  
17 # Create object.
18 0 my $self = bless {}, $class;
19  
20 # Version.
21 0 $self->{'version'} = undef;
22  
23 # Process parameters.
24 0 set_params($self, @params);
25  
26 # Load file with versions.
27 0 $self->{'_versions_file'} = $self->_versions_file;
28 0 my @versions = slurp($self->{'_versions_file'}, {'chomp' => 1});
29 0 $self->{'_versions'} = \@versions;
30  
31 # Set version to last if isn't defined.
32 0 ▶ if (! defined $self->{'version'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"version"}) 0 0 0
33 0 $self->{'version'} = $self->{'_versions'}->[-1];
34 }
35  
36 0 ▶ if ($self->{'version'} !~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"version"} =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/) 0 0 0
37 err 'Schema version has bad format.',
38 0 'Schema version', $self->{'version'},
39 ;
40 }
41  
42 # Load schema.
43 0 $self->{'_schema_module_name'} = $class.'::'."$1\_$2\_$3";
44 0 eval 'require '.$self->{'_schema_module_name'};
45 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Schema::Abstract::EVAL_ERROR) 0 0 0
46 err 'Cannot load Schema module.',
47 0 'Module name', $self->{'_schema_module_name'},
48 'Error', $EVAL_ERROR,
49 ;
50 }
51  
52 0 return $self;
53 }
54  
55 sub list_versions {
56 0 ▶ my $self = shift;
Subroutine list_versions: not called CC=1 SCAR=6.9
Pod documented
57  
58 0 return sort @{$self->{'_versions'}};
59 }
60  
61 sub schema {
62 0 ▶ my $self = shift;
Subroutine schema: not called CC=1 SCAR=6.9
Pod documented
63  
64 0 return $self->{'_schema_module_name'};
65 }
66  
67 sub version {
68 0 ▶ my $self = shift;
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
69  
70 0 return $self->{'version'};
71 }
72  
73 sub _versions_file {
74 0 ▶ my $self = shift;
Subroutine _versions_file: not called CC=1 SCAR=6.9
75  
76 0 err "We need to implement distribution file with Schema versions.";
77  
78 0 return;
79 }
80  
81 6 1;
82  
83 __END__
↑ Summary