blib/lib/DBIx/Squirrel/Result.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 8 / 8 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 100% 73 / 73 CC 9 SCAR 11.3
CC
9
Cov
100%
class_for
6.0
get_column
4.0
BEGIN
1.0
CRAP 3.1
« blib/lib/DBIx/Squirrel/Util.pm ↑ Summary blib/lib/DBIx/Squirrel/Errors.pm »
1 30 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package DBIx::Squirrel::Result;
4  
5 30 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 ▶use DBIx::Squirrel::Errors qw(croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶use DBIx::Squirrel::Util qw(install_sub is_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 30 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 26 our $VERSION = 'v4.2.0';
13  
14 # Croak at the line that called DBIx::Squirrel.
15 26 our @CARP_NOT = @DBIx::Squirrel::Errors::INTERNAL;
16  
17 # Each row class made, with the position of each of its columns' names.
18 26 my %position_of;
19  
20 # Return a column's value, by its name, in any case, or its position,
21 # from 0.
22 23 ▶sub get_column ($self, $column) {
Subroutine get_column: called CC=4 SCAR=13.9
Pod documented
23 my $n
24 = $column =~ m( \A \d+ \z )xa
25 ? $column
26 23 ▶ : $position_of{ref $self}{lc $column};
Branch: 1 branch
BranchTrueFalseTotal
$column =~ / \A \d+ \z /ax ? : 6 17 23
27 23 ▶ croakf 'Expected a column of the row (%s)', $column
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n or $n >= @$self 3 20 23
Condition100%3/3
not defined $n or $n >= @$self
l!l&&r!l&&!r
2120
MC/DC100%2/2
not defined $n or $n >= @$self
not defined $n $n >= @$self
Truth table100%3/3
not(A) or B
A= not defined $nB= $n >= @$self
ABresult
1X1
011
000
28 if !defined $n || $n >= @$self;
29 20 return $self->[$n];
30 }
31  
32 # For DBIx::Squirrel::Results: return the row class, a subclass of the
33 # invocant, for rows with the columns named, making it the first time,
34 # with an accessor for each column.
35 43 ▶sub class_for ($base, $names) {
Subroutine class_for: called CC=6 SCAR=17.9
Pod documented
36 43 my $class = sprintf '%s::Row_%s', $base,
37 substr(sha1_hex(join "\0", @$names), 0, 16);
38 43 ▶ return $class if $position_of{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $position_of{$class} 21 22 43
39 22 my %position;
40 22 for my $n (reverse 0 .. $#$names) {
41 36 $position{$names->[$n]} = $n;
42 }
43 {
44 30 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
45 22 @{ "${class}::ISA" } = ($base);
46 }
47 22 for my $name (keys %position) {
48 35 ▶ next if !is_name($name) || $base->can($name);
Branch: 1 branch
BranchTrueFalseTotal
if not is_name($name) or $base->can($name) 5 30 35
Condition100%3/3
not is_name($name) or $base->can($name)
l!l&&r!l&&!r
2330
MC/DC100%2/2
not is_name($name) or $base->can($name)
not is_name($name) $base->can($name)
Truth table100%3/3
not(A) or B
A= not is_name($name)B= $base->can($name)
ABresult
1X1
011
000
49 30 my $n = $position{$name};
50 # Without a signature, as it's called for each column read, and
51 # a signature costs about 19 ns a call (roadmap 2026-0028).
52 30 ▶ install_sub("${class}::$name", sub { $_[0][$n] });
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine id: called CC=1 SCAR=0.0
Subroutine artistid: called CC=1 SCAR=0.0
53 }
54 22 $position_of{$class} = \%position;
55 22 return $class;
56 }
57  
58 26 1;
59 __END__
« blib/lib/DBIx/Squirrel/Util.pm ↑ Summary blib/lib/DBIx/Squirrel/Errors.pm »