blib/lib/DBIx/Squirrel/Result.pm

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