File Coverage

blib/lib/Schema/Abstract.pm
Criterion Covered Total %
statement 43 44 97.7
branch 6 6 100.0
condition n/a
subroutine 11 11 100.0
pod 4 4 100.0
total 64 65 98.4


line stmt bran cond sub pod time code
1             package Schema::Abstract;
2              
3 6     6   1627416 use strict;
  6         14  
  6         246  
4 6     6   34 use warnings;
  6         13  
  6         486  
5              
6 6     6   1413 use Class::Utils qw(set_params);
  6         32216  
  6         373  
7 6     6   281 use English;
  6         39  
  6         45  
8 6     6   3242 use Error::Pure qw(err);
  6         15  
  6         389  
9 6     6   11914 use Perl6::Slurp qw(slurp);
  6         17808  
  6         45  
10              
11             our $VERSION = 0.05;
12              
13             # Constructor.
14             sub new {
15 10     10 1 124617 my ($class, @params) = @_;
16              
17             # Create object.
18 10         39 my $self = bless {}, $class;
19              
20             # Version.
21 10         60 $self->{'version'} = undef;
22              
23             # Process parameters.
24 10         56 set_params($self, @params);
25              
26             # Load file with versions.
27 10         156 $self->{'_versions_file'} = $self->_versions_file;
28 9         9010 my @versions = slurp($self->{'_versions_file'}, {'chomp' => 1});
29 9         2326 $self->{'_versions'} = \@versions;
30              
31             # Set version to last if isn't defined.
32 9 100       45 if (! defined $self->{'version'}) {
33 4         17 $self->{'version'} = $self->{'_versions'}->[-1];
34             }
35              
36 9 100       69 if ($self->{'version'} !~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/) {
37             err 'Schema version has bad format.',
38 1         7 'Schema version', $self->{'version'},
39             ;
40             }
41              
42             # Load schema.
43 8         58 $self->{'_schema_module_name'} = $class.'::'."$1\_$2\_$3";
44 8         783 eval 'require '.$self->{'_schema_module_name'};
45 8 100       165 if ($EVAL_ERROR) {
46             err 'Cannot load Schema module.',
47 1         7 'Module name', $self->{'_schema_module_name'},
48             'Error', $EVAL_ERROR,
49             ;
50             }
51              
52 7         68 return $self;
53             }
54              
55             sub list_versions {
56 1     1 1 13 my $self = shift;
57              
58 1         2 return sort @{$self->{'_versions'}};
  1         8  
59             }
60              
61             sub schema {
62 2     2 1 82 my $self = shift;
63              
64 2         10 return $self->{'_schema_module_name'};
65             }
66              
67             sub version {
68 2     2 1 19 my $self = shift;
69              
70 2         7 return $self->{'version'};
71             }
72              
73             sub _versions_file {
74 1     1   3 my $self = shift;
75              
76 1         5 err "We need to implement distribution file with Schema versions.";
77              
78 0           return;
79             }
80              
81             1;
82              
83             __END__