| 1 | package Tapper::Schema::TestrunDB::Result::Precondition; | ||||||||||||||||||||||||||||
| 2 | 10 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 10 | $Tapper::Schema::TestrunDB::Result::Precondition::VERSION = '5.0.12'; | |||||||||||||||||||||||||||
| 4 | # ABSTRACT: Tapper - Containing Preconditions for Testruns | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use parent 'DBIx::Class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use YAML::Syck; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 10 | __PACKAGE__->load_components("Core"); | |||||||||||||||||||||||||||
| 13 | 10 | __PACKAGE__->table("precondition"); | |||||||||||||||||||||||||||
| 14 | 10 | __PACKAGE__->add_columns | |||||||||||||||||||||||||||
| 15 | ( | ||||||||||||||||||||||||||||
| 16 | "id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 11, is_auto_increment => 1, }, | ||||||||||||||||||||||||||||
| 17 | "shortname", { data_type => "VARCHAR", default_value => "", is_nullable => 0, size => 255, }, | ||||||||||||||||||||||||||||
| 18 | "precondition", { data_type => "TEXT", default_value => undef, is_nullable => 1, }, | ||||||||||||||||||||||||||||
| 19 | "timeout", { data_type => "INT", default_value => undef, is_nullable => 1, size => 10, }, | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 10 | __PACKAGE__->set_primary_key("id"); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 10 | __PACKAGE__->has_many ( child_pre_precondition => 'Tapper::Schema::TestrunDB::Result::PrePrecondition', { 'foreign.parent_precondition_id' => 'self.id' }); | |||||||||||||||||||||||||||
| 25 | 10 | __PACKAGE__->many_to_many ( child_preconditions => 'child_pre_precondition', 'child' ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 10 | __PACKAGE__->has_many ( parent_pre_precondition => 'Tapper::Schema::TestrunDB::Result::PrePrecondition', { 'foreign.child_precondition_id' => 'self.id' }); | |||||||||||||||||||||||||||
| 28 | 10 | __PACKAGE__->many_to_many ( parent_preconditions => 'parent_pre_precondition', 'parent' ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 10 | __PACKAGE__->has_many ( testrun_precondition => 'Tapper::Schema::TestrunDB::Result::TestrunPrecondition', { 'foreign.precondition_id' => 'self.id' }, { 'join_type' => 'INNER' }); | |||||||||||||||||||||||||||
| 31 | 10 | __PACKAGE__->many_to_many ( parent_testruns => 'testrun_precondition', 'testrun' ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 10 | 1; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # -------------------- methods in results -------------------- | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub one_line { | ||||||||||||||||||||||||||
|
Subroutine
one_line: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | $str =~ s/\\/\\\\/msg; | |||||||||||||||||||||||||||
| 42 | 0 | $str =~ s/\n/\\n/msg; | |||||||||||||||||||||||||||
| 43 | 0 | $str; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub quote { | ||||||||||||||||||||||||||
|
Subroutine
quote: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $d = Data::Dumper->new([$str])->Terse(1)->Indent(0); | |||||||||||||||||||||||||||
| 51 | 0 | $d->Dump; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub quote_and_one_line { | ||||||||||||||||||||||||||
|
Subroutine
quote_and_one_line: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $str = quote($str); | |||||||||||||||||||||||||||
| 59 | 0 | $str =~ s/\n/\\n/msg; | |||||||||||||||||||||||||||
| 60 | 0 | $str; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub to_string | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my ($self, $opt) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $str = ''; | |||||||||||||||||||||||||||
| 69 | 0 | foreach (@{$self->result_source->{_ordered_columns} }) | |||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 0 | my $val = $self->$_; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (defined $val) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( $opt->{quotevalues} && $opt->{nonewlines} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->{"quotevalues"} and $opt->{"nonewlines"}
MC/DC0%0/2
$opt->{"quotevalues"} and $opt->{"nonewlines"}
$opt->{"quotevalues"}
$opt->{"nonewlines"}
Truth table0%0/3
A and B
A= $opt->{"quotevalues"}B= $opt->{"nonewlines"}
| |||||||||||||||||||||||||||||
| 75 | 0 | $val = quote_and_one_line($val); | |||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $val = quote($val) if $opt->{quotevalues}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $val = one_line($val) if $opt->{nonewlines}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } else | ||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 0 | $val = $Tapper::Schema::TestrunDB::NULL; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 0 | $str .= $val . $Tapper::Schema::TestrunDB::DELIM; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | return $str; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 6 | ▶ | sub precondition_as_hash { | ||||||||||||||||||||||||||
|
Subroutine
precondition_as_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 6 | Load(shift->precondition); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub update_content { | ||||||||||||||||||||||||||
|
Subroutine
update_content: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | my ($self, $condition) = @_; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | my $yaml_error = Tapper::Schema::TestrunDB::_yaml_ok($condition); | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | die Tapper::Exception::Param->new($yaml_error) if $yaml_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my @a_conditions = Load($condition); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( scalar @a_conditions > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | say {*STDERR} 'cannot update a single precondition with a set of preconditions'; | |||||||||||||||||||||||||||
| 104 | 0 | return; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my $cond_hash = $a_conditions[0]; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | $self->shortname( $cond_hash->{shortname} ) if $cond_hash->{shortname}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | $self->precondition( $condition ); | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | $self->timeout( $cond_hash->{timeout} ) if $cond_hash->{timeout}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( $self->update ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | return $self->id; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||
| 116 | 0 | say {*STDERR} 'update precondition failed: ' . $self->id; | |||||||||||||||||||||||||||
| 117 | 0 | return; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 10 | 1; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||