| 1 | package Test::Pcuke::Gherkin::Node::Table; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | ▶ | use Scalar::Util qw{blessed}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | ▶ | use base 'Test::Pcuke::Gherkin::Node'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | ▶ | use Test::Pcuke::Gherkin::Node::Table::Row; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Test::Pcuke::Gherkin::Node::Table - table in Gherkin | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | TODO Synopsis | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | use Test::Pcuke::Gherkin::Node::Table; | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | my $table = Test::Pcuke::Gherkin::Node::Table->new(); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =head1 METHODS | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head2 new | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 4 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=13.6
Pod
documented
| |||||||||||||||||||||
| 32 | 4 | my ($self, $args) = @_; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 4 | $args->{'_nsteps'} = {pass=>0, undef=>0, fail=>0}; | |||||||||||||||||||
| 35 | 4 | $args->{'_nscenarios'} = {pass=>0, undef=>0, fail=>0}; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 4 | my $new_instance = $self->SUPER::new( | |||||||||||||||||||
| 38 | immutables => [qw{executor}], | ||||||||||||||||||||
| 39 | properties => [qw{_nsteps _nscenarios}], | ||||||||||||||||||||
| 40 | args => $args, | ||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 4 | ▶ | if ( $args->{headings} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | $new_instance->set_headings( $args->{headings} ); | |||||||||||||||||||
| 45 | 0 | ▶ | if ( $args->{rows} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | $new_instance->add_rows( $args->{rows} ); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 4 | return $new_instance; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 8 | ▶ | sub headings { $_[0]->_get_immutable('headings') || [] } | ||||||||||||||||||
|
Subroutine
headings: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 3 | ▶ | sub set_headings { | ||||||||||||||||||
|
Subroutine
set_headings: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 57 | 3 | my ($self, $headings) = @_; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 3 | ▶ | if ( ref $headings ne 'ARRAY' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 2 | local $@; | |||||||||||||||||||
| 61 | 2 | $headings = eval { [ keys %{$headings->data}] }; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 2 | ▶ | confess "headings must be either arrayref or Table::Row" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | if $@; | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 3 | $self->_set_immutable('headings', $headings); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 9 | ▶ | sub add_row { | ||||||||||||||||||
|
Subroutine
add_row: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | 9 | my ($self, $row) = @_; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 9 | ▶ | if ( ref $row eq 'ARRAY' ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 74 | 2 | $row = $self->_make_row( $row ); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | ▶ | elsif ( blessed $row && $row->can('data') ) { # probably isa Table::Row | |||||||||||||||||||
|
Condition66%2/3
builtin::blessed($row) and $row->can("data")
MC/DC50%1/2
builtin::blessed($row) and $row->can("data")
builtin::blessed($row)
$row->can("data")
Truth table66%2/3
A and B
A= builtin::blessed($row)B= $row->can("data")
| |||||||||||||||||||||
| 77 | 6 | $self->_set_check_headings($row); # dies if headings differ | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||
| 80 | 1 | confess "add_row takes either arrayref or Table::Row"; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 7 | $row->set_executor( $self->_get_immutable('executor') ); | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 7 | $self->_add_property('rows', $row); | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 6 | ▶ | sub _set_check_headings { | ||||||||||||||||||
|
Subroutine
_set_check_headings: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 89 | 6 | my ($self, $row) = @_; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 6 | my @t_heads = sort @{ $self->headings }; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 6 | ▶ | if ( ! @t_heads ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 2 | $self->set_headings( $row ); | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||
| 97 | 4 | my @r_heads = sort keys %{ $row->data }; | |||||||||||||||||||
| 98 | 4 | ▶ | confess "incorrect number of columns in the row" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | if @r_heads != @t_heads; | ||||||||||||||||||||
| 100 | 4 | ▶ | confess "headings of a row are different from that of the table!" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | if join('', @t_heads) ne join('',@r_heads); | ||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 2 | ▶ | sub _make_row { | ||||||||||||||||||
|
Subroutine
_make_row: called CC=3 SCAR=11.2
| |||||||||||||||||||||
| 106 | 2 | my ($self, $data) = @_; | |||||||||||||||||||
| 107 | 2 | my ($hash, $row); | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 2 | my @headings = @{ $self->_get_immutable('headings') }; | |||||||||||||||||||
| 110 | 2 | ▶ | $self->_no_headings_exception() unless @headings; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 2 | ▶ | if ( @headings == @$data ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | 2 | $hash = { map { shift @headings => $_ } @$data }; | |||||||||||||||||||
| 114 | 2 | $row = Test::Pcuke::Gherkin::Node::Table::Row->new(); | |||||||||||||||||||
| 115 | 2 | $row->set_data( $hash ); | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||
| 118 | 0 | confess "The number of columns in the row must correspond to the number of headings"; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 2 | return $row; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 1 | ▶ | sub add_rows { | ||||||||||||||||||
|
Subroutine
add_rows: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 125 | 1 | my ($self, $rows) = @_; | |||||||||||||||||||
| 126 | 1 | foreach (@$rows) { | |||||||||||||||||||
| 127 | 3 | $self->add_row($_); | |||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 4 | ▶ | sub rows { $_[0]->_get_property('rows') } | ||||||||||||||||||
|
Subroutine
rows: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 2 | ▶ | sub hashes { | ||||||||||||||||||
|
Subroutine
hashes: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 134 | 2 | my ($self) = @_; | |||||||||||||||||||
| 135 | 2 | my $result; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 2 | for my $row ( @{ $self->rows } ) { | |||||||||||||||||||
| 138 | 3 | push @$result, $row->data; | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 2 | return $result; | |||||||||||||||||||
| 142 | }; | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 1 | ▶ | sub execute { | ||||||||||||||||||
|
Subroutine
execute: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 145 | 1 | my ($self, $steps, $background) = @_; | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 1 | for my $row ( @{ $self->rows } ) { | |||||||||||||||||||
| 148 | 3 | $row->execute($steps, $background); | |||||||||||||||||||
| 149 | 3 | $self->collect_stats( $row ); | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 3 | ▶ | sub collect_stats { | ||||||||||||||||||
|
Subroutine
collect_stats: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 154 | 3 | my ($self, $row) = @_; | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 3 | my $nsteps = $self->nsteps; | |||||||||||||||||||
| 157 | 3 | my $nscenarios = $self->nscenarios; | |||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 3 | my $r_nsteps = $row->nsteps; | |||||||||||||||||||
| 160 | 3 | my $r_nscenarios = $row->nscenarios; | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 3 | for (qw{pass fail undef}) { | |||||||||||||||||||
| 163 | 9 | $nsteps->{$_} += $r_nsteps->{$_}; | |||||||||||||||||||
| 164 | 9 | $nscenarios->{$_} += $r_nscenarios->{$_}; | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | 3 | $self->_set_property('_nsteps', $nsteps); | |||||||||||||||||||
| 168 | 3 | $self->_set_property('_nscenarios', $nscenarios); | |||||||||||||||||||
| 169 | } | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 4 | ▶ | sub nsteps { | ||||||||||||||||||
|
Subroutine
nsteps: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 172 | 4 | my ($self, $status) = @_; | |||||||||||||||||||
| 173 | 4 | my $nsteps = $self->_get_property('_nsteps'); | |||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | return $status ? | ||||||||||||||||||||
| 176 | 4 | ▶ | $nsteps->{$status} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 177 | : $nsteps; | ||||||||||||||||||||
| 178 | } | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 4 | ▶ | sub nscenarios { | ||||||||||||||||||
|
Subroutine
nscenarios: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 181 | 4 | my ($self, $status) = @_; | |||||||||||||||||||
| 182 | 4 | my $nscenarios = $self->_get_property('_nscenarios'); | |||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | return $status ? | ||||||||||||||||||||
| 185 | 4 | ▶ | $nscenarios->{$status} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 186 | : $nscenarios; | ||||||||||||||||||||
| 187 | } | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | 0 | ▶ | sub _no_headings_exception { confess "headings must be set before adding the rows" } | ||||||||||||||||||
|
Subroutine
_no_headings_exception: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 3 | 1; # End of Test::Pcuke::Gherkin::Node::Table | |||||||||||||||||||
| 194 | __END__ | ||||||||||||||||||||