| 1 | package Tapper::Cmd::Precondition; | ||||||||||||||||||||||||||||
| 2 | 8 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 8 | $Tapper::Cmd::Precondition::VERSION = '5.0.14'; | |||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use YAML::Syck; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Kwalify; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use parent 'Tapper::Cmd'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub die_on_invalid_precondition | ||||||||||||||||||||||||||||
| 14 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
die_on_invalid_precondition: called CC=6 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 7 | my ($self, $preconditions, $schema) = @_; | |||||||||||||||||||||||||||
| 16 | 7 | ▶ | if (not ($schema and ref($schema) eq 'HASH') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$schema and ref $schema eq "HASH"
MC/DC0%0/2
$schema and ref $schema eq "HASH"
$schema
ref $schema eq "HASH"
Truth table33%1/3
A and B
A= $schemaB= ref $schema eq "HASH"
| |||||||||||||||||||||||||||||
| 17 | 7 | $schema = | |||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||
| 19 | type => 'map', | ||||||||||||||||||||||||||||
| 20 | mapping => | ||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | precondition_type => | ||||||||||||||||||||||||||||
| 23 | { type => 'str', | ||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | '=' => | ||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | type => 'any', | ||||||||||||||||||||||||||||
| 29 | required => 1, | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 7 | ▶ | $preconditions = [ $preconditions] unless ref($preconditions) eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | precondition: | ||||||||||||||||||||||||||||
| 36 | 7 | foreach my $precondition (@$preconditions) { | |||||||||||||||||||||||||||
| 37 | # undefined preconditions are caused by tapper headers or a "---\n" line at the end | ||||||||||||||||||||||||||||
| 38 | 22 | ▶ | next precondition unless defined($precondition); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 21 | Kwalify::validate($schema, $precondition); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 6 | return 0; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 7 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 7 | my ($self, $input, $schema) = @_; | |||||||||||||||||||||||||||
| 47 | 7 | ▶ | if (ref $input eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 5 | $self->die_on_invalid_precondition($input, $schema); | |||||||||||||||||||||||||||
| 49 | 5 | return $self->schema->resultset('Precondition')->add($input); | |||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||
| 51 | 2 | ▶ | $input .= "\n" unless $input =~ /\n$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 2 | my @yaml = Load($input); | |||||||||||||||||||||||||||
| 53 | 2 | $self->die_on_invalid_precondition(\@yaml, $schema); | |||||||||||||||||||||||||||
| 54 | 1 | return $self->schema->resultset('Precondition')->add(\@yaml); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $id, $condition) = @_; | |||||||||||||||||||||||||||
| 61 | 0 | my $precondition = $self->schema->resultset('Precondition')->find($id); | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | die "Precondition with id $id not found\n" if not $precondition; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | return $precondition->update_content($condition); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub del { | ||||||||||||||||||||||||||
|
Subroutine
del: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 1 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 71 | 1 | my $precondition = $self->schema->resultset('Precondition')->find($id); | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | return qq(No precondition with id "$id" found) if not $precondition;; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 1 | $precondition->delete(); | |||||||||||||||||||||||||||
| 74 | 1 | return 0; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 8 | 1; # End of Tapper::Cmd::Testrun | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||