| 1 | package File::DataClass::ResultSet; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use File::DataClass::Constants qw( EXCEPTION_CLASS FALSE TRUE ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use File::DataClass::Functions qw( is_arrayref is_hashref is_member throw ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::DataClass::List; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::DataClass::Result; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::DataClass::Types qw( ArrayRef ClassName | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | HashRef Int Maybe Object Str ); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Subclass::Of; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Unexpected::Functions qw( RecordNotFound Unspecified ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my $class_stash = {}; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # Private functions | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | my $_build_operators = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__operators: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | 'eq' => sub { return $_[ 0 ] eq $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | '==' => sub { return $_[ 0 ] == $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | 'ne' => sub { return $_[ 0 ] ne $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | '!=' => sub { return $_[ 0 ] != $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | '>' => sub { return $_[ 0 ] > $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | '>=' => sub { return $_[ 0 ] >= $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | '<' => sub { return $_[ 0 ] < $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | '<=' => sub { return $_[ 0 ] <= $_[ 1 ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | '=~' => sub { my $re = $_[ 1 ]; return $_[ 0 ] =~ qr{ $re }mx }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | '!~' => sub { my $re = $_[ 1 ]; return $_[ 0 ] !~ qr{ $re }mx }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Public attributes | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | has 'list_class' => is => 'ro', isa => ClassName, | |||||||||||||||||||||||||||||||||||||||||
| 36 | default => 'File::DataClass::List'; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | has 'result_class' => is => 'ro', isa => ClassName, | |||||||||||||||||||||||||||||||||||||||||
| 39 | default => 'File::DataClass::Result'; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | has 'result_source' => is => 'ro', isa => Object, | |||||||||||||||||||||||||||||||||||||||||
| 42 | handles => [ qw( attributes defaults label_attr path storage ) ], | ||||||||||||||||||||||||||||||||||||||||||
| 43 | required => TRUE, weak_ref => TRUE; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | has '_iterator' => is => 'rw', isa => Int, default => 0, | |||||||||||||||||||||||||||||||||||||||||
| 46 | init_arg => undef; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | has '_operators' => is => 'lazy', isa => HashRef, | |||||||||||||||||||||||||||||||||||||||||
| 49 | builder => $_build_operators; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | has '_results' => is => 'rw', isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 19 | ▶ | builder => sub { [] }, init_arg => undef; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__results: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # Private methods | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | ▶ | my $_get_attr_meta = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | my ($types, $source, $values, $attr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | my $sdef = $source->defaults->{ $attr }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | my $type = $source->types->{ $attr } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | ▶ | // $types->{ ref $sdef || ref $values->{ $attr } || 'SCALAR' }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%6/8
$source->types->{$attr} // $$types{ref $sdef or ref $values->{$attr} or "SCALAR"}
ref $sdef || ref $values->{$attr} || 'SCALAR'
ref $sdef or ref $values->{$attr}
MC/DC0%0/2
$source->types->{$attr} // $$types{ref $sdef or ref $values->{$attr} or "SCALAR"}
$source->types->{$attr}
$$types{ref $sdef or ref $values->{$attr} or "SCALAR"}
MC/DC50%1/2
ref $sdef || ref $values->{$attr} || 'SCALAR'
ref $sdef
ref $values->{$attr}
Truth table66%2/3
A // B
A= $source->types->{$attr}B= $$types{ref $sdef or ref $values->{$attr} or "SCALAR"}
Truth table66%2/3
A or B
A= ref $sdefB= ref $values->{$attr}
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | return [ is => 'rw', isa => $type ]; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 51 | ▶ | my $_new_result_class = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 51 | my ($class, $source, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 51 | my $name = "${class}::".(ucfirst $source->name); | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 51 | ▶ | exists $class_stash->{ $name } and return $class_stash->{ $name }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | my $except = 'delete | id | insert | name | result_source | update'; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | my %types = ( 'ARRAY', Maybe[ArrayRef], | |||||||||||||||||||||||||||||||||||||||||
| 74 | 'HASH', Maybe[HashRef], | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 'SCALAR', Maybe[Str], ); | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | my @attrs = map { $_ => $_get_attr_meta->( \%types, $source, $values, $_ )} | |||||||||||||||||||||||||||||||||||||||||
| 77 | 7 | grep { not m{ \A (?: $except ) \z }mx } | |||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | @{ $source->attributes }; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | return $class_stash->{ $name } = subclass_of | |||||||||||||||||||||||||||||||||||||||||
| 81 | ( $class, -package => $name, -has => [ @attrs ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 51 | ▶ | my $_create_result = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 51 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 51 | my $attr = { %{ $self->defaults }, result_source => $self->result_source }; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 51 | ▶ | for (grep { exists $args->{ $_ } and defined $args->{ $_ } } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
exists $args->{$_} && defined $args->{$_}
MC/DC50%1/2
exists $args->{$_} && defined $args->{$_}
exists $args->{$_}
defined $args->{$_}
Truth table66%2/3
A && B
A= exists $args->{$_}B= defined $args->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 51 | @{ $self->attributes }, 'id', 'name') { | |||||||||||||||||||||||||||||||||||||||||
| 91 | 141 | $attr->{ $_ } = $args->{ $_ }; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 51 | my $class = $_new_result_class-> | |||||||||||||||||||||||||||||||||||||||||
| 95 | ( $self->result_class, $self->result_source, $attr ); | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 51 | return $class->new( $attr ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 34 | ▶ | my $_eval_op = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 34 | my ($self, $lhs, $op, $rhs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 34 | ▶ | my $subr = $self->_operators->{ $op } or return FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 34 | ▶ | $_ or return FALSE for (map { $subr->( $_, $rhs ) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | (is_arrayref $lhs) ? @{ $lhs } : ( $lhs )); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 21 | return TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | my $_push = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my ($self, $id, $attr, $items) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | my $attrs = { %{ $self->select->{ $id } // {} }, id => $id }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->select->{$id} // {}
MC/DC0%0/1
$self->select->{$id} // {}
$self->select->{$id}
Truth table50%1/2
A
A= $self->select->{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | my $list = [ @{ $attrs->{ $attr } // [] } ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attrs->{$attr} // []
MC/DC0%0/1
$attrs->{$attr} // []
$attrs->{$attr}
Truth table50%1/2
A
A= $attrs->{$attr}
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | my $in = []; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | for my $item (grep { not is_member $_, $list } @{ $items }) { | |||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | CORE::push @{ $list }, $item; CORE::push @{ $in }, $item; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | $attrs->{ $attr } = $list; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | return ($attrs, $in); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | my $_splice = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my ($self, $id, $attr, $items) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | my $attrs = { %{ $self->select->{ $id } // {} }, id => $id }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->select->{$id} // {}
MC/DC0%0/1
$self->select->{$id} // {}
$self->select->{$id}
Truth table50%1/2
A
A= $self->select->{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | my $list = [ @{ $attrs->{ $attr } // [] } ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attrs->{$attr} // []
MC/DC0%0/1
$attrs->{$attr} // []
$attrs->{$attr}
Truth table50%1/2
A
A= $attrs->{$attr}
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my $out = []; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | for my $item (@{ $items }) { | |||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | defined $list->[ 0 ] or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | for (0 .. $#{ $list }) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | if ($list->[ $_ ] eq $item) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | CORE::splice @{ $list }, $_, 1; CORE::push @{ $out }, $item; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | $attrs->{ $attr } = $list; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return ($attrs, $out); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 49 | ▶ | my $_txn_do = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 49 | my ($self, $coderef) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 49 | return $self->storage->txn_do( $self->path, $coderef ); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 11 | ▶ | my $_update_result = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 11 | my ($self, $result, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 11 | for my $attr (grep { exists $args->{ $_ } } @{ $self->attributes }) { | |||||||||||||||||||||||||||||||||||||||||
| 158 | 15 | $result->$attr( $args->{ $attr } ); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 11 | return $result->update; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 36 | ▶ | my $_validate_params = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 36 | ▶ | my ($self, $args) = @_; $args //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args //= {}
MC/DC100%1/1
$args //= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 36 | ▶ | my $id = (is_hashref $args) ? ($args->{id} // $args->{name}) : $args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$args->{"id"} // $args->{"name"}
MC/DC100%2/2
$args->{"id"} // $args->{"name"}
$args->{"id"}
$args->{"name"}
Truth table100%3/3
A // B
A= $args->{"id"}B= $args->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 36 | ▶ | $id or throw Unspecified, [ 'record id' ], level => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 34 | return $id; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 43 | ▶ | my $_eval_clause = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=24.5
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 43 | my ($self, $clause, $lhs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 43 | ▶ | if (is_hashref $clause) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 34 | for (keys %{ $clause }) { | |||||||||||||||||||||||||||||||||||||||||
| 179 | 34 | ▶ | $self->$_eval_op( $lhs, $_, $clause->{ $_ } ) or return FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 21 | return TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | elsif (is_arrayref $clause) { # TODO: Handle case of 2 arrays | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return (is_arrayref $lhs) ? FALSE : (is_member $lhs, $clause); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 9 | ▶ | return (is_arrayref $lhs) ? ((is_member $clause, $lhs) ? TRUE : FALSE) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | : ($clause eq $lhs ? TRUE : FALSE); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 25 | ▶ | my $_find = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 25 | my ($self, $id) = @_; my $results = $self->select; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 25 | ▶ | ($id and exists $results->{ $id }) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$id and exists $results->{$id}
MC/DC50%1/2
$id and exists $results->{$id}
$id
exists $results->{$id}
Truth table66%2/3
A and B
A= $idB= exists $results->{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 20 | my $attrs = { %{ $results->{ $id } }, id => $id }; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 20 | return $self->$_create_result( $attrs ); | |||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | my $_list = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | my ($self, $id) = @_; my ($attr, $attrs, $labels); my $found = FALSE; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | my $results = $self->select; my $list = [ sort keys %{ $results } ]; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | $attr = $self->label_attr | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | and $labels = { map { $_ => $results->{ $_ }->{ $attr } } @{ $list } }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | ▶ | if ($id and exists $results->{ $id }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$id and exists $results->{$id}
MC/DC50%1/2
$id and exists $results->{$id}
$id
exists $results->{$id}
Truth table66%2/3
A and B
A= $idB= exists $results->{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | $attrs = { %{ $results->{ $id } }, id => $id }; $found = TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | else { $attrs = { id => $id } } | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | my $result = $self->$_create_result( $attrs ); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | $attrs = { found => $found, list => $list, result => $result, }; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | ▶ | $labels and $attrs->{labels} = $labels; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | return $self->list_class->new( $attrs ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 45 | ▶ | my $_eval_criteria = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 45 | my ($self, $criteria, $attrs) = @_; my $lhs; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 45 | for my $k (keys %{ $criteria }) { | |||||||||||||||||||||||||||||||||||||||||
| 226 | 45 | ▶ | defined ($lhs = $attrs->{ $k eq 'name' ? 'id' : $k }) or return FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 43 | ▶ | $self->$_eval_clause( $criteria->{ $k }, $lhs ) or return FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 26 | return TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 6 | ▶ | my $_find_and_update = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 6 | my ($self, $args) = @_; my $id = $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | ▶ | my $result = $self->$_find( $id ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | or throw RecordNotFound, [ $self->path, $id ]; | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 6 | return $self->$_update_result( $result, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 17 | ▶ | my $_search = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 17 | my ($self, $where) = @_; my $results = $self->_results; my @tmp; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 17 | ▶ | if (not defined $results->[ 0 ]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 14 | $results = $self->select; | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 14 | for (keys %{ $results }) { | |||||||||||||||||||||||||||||||||||||||||
| 249 | 42 | my $attrs = { %{ $results->{ $_ } }, id => $_ }; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 42 | ▶ | if (not $where or $self->$_eval_criteria( $where, $attrs )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $where or $self->$_eval_criteria($where, $attrs)
MC/DC50%1/2
not $where or $self->$_eval_criteria($where, $attrs)
not $where
$self->$_eval_criteria($where, $attrs)
Truth table66%2/3
not(A) or B
A= not $whereB= $self->$_eval_criteria($where, $attrs)
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 23 | CORE::push @{ $self->_results }, $self->$_create_result( $attrs ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | ▶ | elsif ($where and defined $results->[ 0 ]) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$where and defined $results->[0]
MC/DC0%0/2
$where and defined $results->[0]
$where
defined $results->[0]
Truth table33%1/3
A and B
A= $whereB= defined $results->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 3 | for (@{ $results }) { | |||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | ▶ | $self->$_eval_criteria( $where, $_ ) and CORE::push @tmp, $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | $self->_results( \@tmp ); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 17 | ▶ | return wantarray ? $self->all : $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | # Public methods | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 12 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 12 | my $self = shift; return @{ $self->_results }; | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 6 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 6 | my ($self, $args) = @_; $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 4 | ▶ | return $self->$_txn_do( sub { $self->$_create_result( $args )->insert } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | ▶ | sub create_or_update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_or_update: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | my ($self, $args) = @_; my $id = $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 5 | ▶ | return $self->$_txn_do( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | ▶ | my $result = $self->$_find( $id ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | or return $self->$_create_result( $args )->insert; | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 3 | return $self->$_update_result( $result, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 8 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 8 | my ($self, $args) = @_; my $id = $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 8 | my $path = $self->path; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 8 | ▶ | my $optional = (is_hashref $args) ? $args->{optional} : FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 8 | ▶ | my $res = $self->$_txn_do( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 8 | ▶ | my $result; unless ($result = $self->$_find( $id )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 3 | ▶ | $optional or throw RecordNotFound, [ $path, $id ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | return FALSE; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | $result->delete | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 5 | ▶ | or throw 'File [_1] source [_2] not deleted', [ $path, $id ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | return TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 8 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 6 | ▶ | return $res ? $id : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 6 | ▶ | sub find { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 6 | my ($self, $args) = @_; my $id = $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 6 | ▶ | return $self->$_txn_do( sub { $self->$_find( $id ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | ▶ | sub find_and_update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_and_update: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | my ($self, $args) = @_; $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ▶ | return $self->$_txn_do( sub { $self->$_find_and_update( $args ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | ▶ | sub first { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | my $self = shift; return $self->_results->[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | sub last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | my $self = shift; return $self->_results->[ -1 ]; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 2 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 2 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | my $id = (is_hashref $args) ? $args->{id} // $args->{name} : $args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{"id"} // $args->{"name"}
MC/DC0%0/2
$args->{"id"} // $args->{"name"}
$args->{"id"}
$args->{"name"}
Truth table33%1/3
A // B
A= $args->{"id"}B= $args->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | return $self->$_txn_do( sub { $self->$_list( $id ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 3 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 3 | my $index = $self->_iterator; $self->_iterator( $index + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | return $self->_results->[ $index ]; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | ▶ | sub push { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | my ($self, $args) = @_; my $id = $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ▶ | my $list = $args->{list} or throw Unspecified, [ 'list' ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | ▶ | my $items = $args->{items} // []; my ($added, $attrs); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"items"} // []
MC/DC100%1/1
$args->{"items"} // []
$args->{"items"}
Truth table100%2/2
A
A= $args->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 2 | ▶ | $items->[ 0 ] or throw 'List contains no items'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | my $res = $self->$_txn_do( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | ($attrs, $added) = $self->$_push( $id, $list, $items ); | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | return $self->$_find_and_update( $attrs ); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | return $res ? $added : FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | my $self = shift; return $self->_iterator( 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 43 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 43 | return $self->storage->select( $self->path, $self->result_source->name ); | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 17 | ▶ | sub search { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 17 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 17 | ▶ | return $self->$_txn_do( sub { $self->$_search( $args ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | ▶ | sub splice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
splice: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | my ($self, $args) = @_; my $id = $self->$_validate_params( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 2 | ▶ | my $list = $args->{list} or throw Unspecified, [ 'list' ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | ▶ | my $items = $args->{items} // []; my ($attrs, $removed); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"items"} // []
MC/DC100%1/1
$args->{"items"} // []
$args->{"items"}
Truth table100%2/2
A
A= $args->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | ▶ | $items->[ 0 ] or throw 'List contains no items'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | my $res = $self->$_txn_do( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | ($attrs, $removed) = $self->$_splice( $id, $list, $items ); | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | return $self->$_find_and_update( $attrs ); | |||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | ▶ | return $res ? $removed : FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 4 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 4 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 4 | ▶ | if (my $id = $args->{id} // $args->{name}) { # Deprecated | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$args->{"id"} // $args->{"name"}
MC/DC100%2/2
$args->{"id"} // $args->{"name"}
$args->{"id"}
$args->{"name"}
Truth table100%3/3
A // B
A= $args->{"id"}B= $args->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | ▶ | return $self->$_txn_do( sub { $self->$_find_and_update( $args ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | return $self->$_txn_do( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | my $updated = FALSE; | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | for my $result (@{ $self->_results }) { | |||||||||||||||||||||||||||||||||||||||||
| 404 | 2 | ▶ | my $res = $self->$_update_result( $result, $args ); $updated ||= $res; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$updated ||= $res
MC/DC0%0/2
$updated ||= $res
$updated
$res
Truth table66%2/3
A ||= B
A= $updatedB= $res
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | return $updated; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | __END__ | ||||||||||||||||||||||||||||||||||||||||||