| 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.03; | |||||||||
| 12 | |||||||||||
| 13 | # Constructor. | ||||||||||
| 14 | sub new { | ||||||||||
| 15 | 7 | ▶ | my ($class, @params) = @_; | ||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 16 | |||||||||||
| 17 | # Create object. | ||||||||||
| 18 | 7 | my $self = bless {}, $class; | |||||||||
| 19 | |||||||||||
| 20 | # Version. | ||||||||||
| 21 | 7 | $self->{'version'} = undef; | |||||||||
| 22 | |||||||||||
| 23 | # Process parameters. | ||||||||||
| 24 | 7 | set_params($self, @params); | |||||||||
| 25 | |||||||||||
| 26 | # Load file with versions. | ||||||||||
| 27 | 7 | $self->{'_versions_file'} = $self->_versions_file; | |||||||||
| 28 | 7 | my @versions = slurp($self->{'_versions_file'}, {'chomp' => 1}); | |||||||||
| 29 | 7 | $self->{'_versions'} = \@versions; | |||||||||
| 30 | |||||||||||
| 31 | # Set version to last if isn't defined. | ||||||||||
| 32 | 7 | ▶ | if (! defined $self->{'version'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 4 | $self->{'version'} = $self->{'_versions'}->[-1]; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 7 | ▶ | if ($self->{'version'} !~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | err 'Schema version has bad format.', | ||||||||||
| 38 | 0 | 'Schema version', $self->{'version'}, | |||||||||
| 39 | ; | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # Load schema. | ||||||||||
| 43 | 7 | $self->{'_schema_module_name'} = $class.'::'."$1\_$2\_$3"; | |||||||||
| 44 | 7 | eval 'require '.$self->{'_schema_module_name'}; | |||||||||
| 45 | 7 | ▶ | if ($EVAL_ERROR) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | err 'Cannot load Schema module.', | ||||||||||
| 47 | 0 | 'Module name', $self->{'_schema_module_name'}, | |||||||||
| 48 | 'Error', $EVAL_ERROR, | ||||||||||
| 49 | ; | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 7 | return $self; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | sub list_versions { | ||||||||||
| 56 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
list_versions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | 1 | return sort @{$self->{'_versions'}}; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub schema { | ||||||||||
| 62 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
schema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 63 | |||||||||||
| 64 | 2 | return $self->{'_schema_module_name'}; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | sub version { | ||||||||||
| 68 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 69 | |||||||||||
| 70 | 2 | 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__ | ||||||||||