File Coverage

blib/lib/Schema/Data.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::Data;
2              
3 6     6   75473 use strict;
  6         35  
  6         164  
4 6     6   30 use warnings;
  6         21  
  6         160  
5              
6 6     6   987 use Class::Utils qw(set_params);
  6         26409  
  6         286  
7 6     6   195 use English;
  6         11  
  6         35  
8 6     6   2935 use Error::Pure qw(err);
  6         24  
  6         282  
9 6     6   3273 use Perl6::Slurp qw(slurp);
  6         9538  
  6         50  
10              
11             our $VERSION = 0.06;
12              
13             sub new {
14 7     7 1 82364 my ($class, @params) = @_;
15              
16             # Create object.
17 7         22 my $self = bless {}, $class;
18              
19             # Version.
20 7         29 $self->{'version'} = undef;
21              
22             # Process parameters.
23 7         31 set_params($self, @params);
24              
25             # Load file with versions.
26 7         96 $self->{'_versions_file'} = $self->_versions_file;
27 7         5038 my @versions = slurp($self->{'_versions_file'}, {'chomp' => 1});
28 7         1605 $self->{'_versions'} = \@versions;
29              
30             # Set version to last if isn't defined.
31 7 100       29 if (! defined $self->{'version'}) {
32 4         12 $self->{'version'} = $self->{'_versions'}->[-1];
33             }
34              
35 7 50       50 if ($self->{'version'} !~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/) {
36             err 'Schema data version has bad format.',
37 0         0 'Schema data version', $self->{'version'},
38             ;
39             }
40              
41             # Load schema.
42 7         42 $self->{'_schema_data_module'} = $class.'::'."$1\_$2\_$3";
43 7         446 eval 'require '.$self->{'_schema_data_module'};
44 7 50       128 if ($EVAL_ERROR) {
45             err 'Cannot load Schema data module.',
46 0         0 'Module name', $self->{'_schema_data_module'},
47             'Error', $EVAL_ERROR,
48             ;
49             }
50              
51 7         61 return $self;
52             }
53              
54             sub list_versions {
55 1     1 1 10 my $self = shift;
56              
57 1         9 return sort @{$self->{'_versions'}};
  1         16  
58             }
59              
60             sub schema_data {
61 2     2 1 19 my $self = shift;
62              
63 2         18 return $self->{'_schema_data_module'};
64             }
65              
66             sub version {
67 2     2 1 15 my $self = shift;
68              
69 2         20 return $self->{'version'};
70             }
71              
72             sub _versions_file {
73 0     0     my $self = shift;
74              
75 0           err "We need to implement distribution file with Schema data versions.";
76              
77 0           return;
78             }
79              
80             1;
81              
82              
83             __END__