File Coverage

blib/lib/Schema/Abstract.pm
Criterion Covered Total %
statement 39 44 88.6
branch 4 6 66.6
condition n/a
subroutine 10 11 90.9
pod 4 4 100.0
total 57 65 87.6


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