lib/DB/Object/Fields/Unknown.pm

filter: Statementstmt 28.4% 25 / 88 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 22.8% 8 / 35 Podpod 50.0% 5 / 10 totaltotal 21.1% 38 / 180 CC 18 SCAR 35.1
CC
18
Cov
20%
THAW
110.0
FREEZE
72.0
init
6.0
CRAP 33.6
« lib/DB/Object/SQLite/Statement.pm ↑ Summary lib/DB/Object/Query/Elements.pm »
1 ##----------------------------------------------------------------------------
2 ## Database Object Interface - ~/lib/DB/Object/Fields/Unknown.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/12/21
7 ## Modified 2026/03/22
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package DB::Object::Fields::Unknown;
14 BEGIN
15 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=1.1
16 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 warnings::register_categories( 'DB::Object' );
19 1 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use vars qw( $VERSION $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=4.8
22 # '""' => \&as_string,
23 0 ▶ 'bool' => sub{$_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 ▶ '+' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 ▶ '-' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 ▶ '*' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 ▶ '/' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 ▶ '%' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 ▶ '<' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 ▶ '>' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 ▶ '<=' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 ▶ '>=' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 ▶ '!=' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 ▶ '<<' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 ▶ '>>' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 ▶ '&' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 ▶ '^' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 ▶ '|' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 ▶ '==' => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 1 fallback => 1,
41 1 );
42 1 our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
43 1 our $VERSION = 'v0.2.0';
44 };
45  
46 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 sub init
50 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
51 0 my $self = shift( @_ );
52 0 $self->{error} = undef;
53 0 $self->{field} = undef;
54 0 $self->{table} = undef;
55 0 $self->{_init_strict_use_sub} = 1;
56 0 $self->{_exception_class} = $EXCEPTION_CLASS;
57 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
58 0 return( $self );
59 }
60  
61 0 ▶sub as_string { return( shift->error->scalar ); }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
62  
63 0 ▶sub error { return( shift->_set_get_scalar_as_object( 'error', @_ ) ); }
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
64  
65 0 ▶sub field { return( shift->_set_get_scalar_as_object( 'field', @_ ) ); }
Subroutine field: not called CC=1 SCAR=6.9
Pod documented
66  
67 0 ▶sub table { return( shift->_set_get_scalar_as_object( 'table', @_ ) ); }
Subroutine table: not called CC=1 SCAR=6.9
Pod documented
68  
69 # NOTE: For CBOR and Sereal
70 sub FREEZE
71 0 ▶{
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
72 0 my $self = CORE::shift( @_ );
73 0 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
74 0 my $class = CORE::ref( $self );
75  
76 # We keep a strict allow-list to avoid accidentally freezing DBI handles or other
77 # process-local state.
78 # 2026-01-29: I removed 'query_object' in an effort to reduce memory consumption. Let's see...
79 0 my @props = qw(
80 field table
81 );
82  
83 0 my $hash = {};
84 0 foreach my $prop ( @props )
85 {
86 0 ▶ if( CORE::exists( $self->{ $prop } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE") 0 0 0
Condition0%0/6
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
!ll&&!rl&&r
000
exists $self->{$prop} and defined $self->{$prop}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
exists $self->{$prop} defined $self->{$prop} ref $self->{$prop} ne "CODE"
Truth table0%0/4
A and B and C
A= exists $self->{$prop}B= defined $self->{$prop}C= ref $self->{$prop} ne "CODE"
ABCresult
0XX0
10X0
1100
1111
87 defined( $self->{ $prop } ) &&
88 CORE::ref( $self->{ $prop } ) ne 'CODE' )
89 {
90 0 $hash->{ $prop } = $self->{ $prop };
91 }
92 }
93  
94 # Return an array reference rather than a list so this works with Sereal and CBOR.
95 # Before Sereal version 4.023, Sereal did not support multiple values returned.
96 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
97 {
98 0 require Sereal::Encoder;
99 0 require version;
100  
101 0 ▶ if( version->parse( Sereal::Encoder->VERSION ) < version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) < "version"->parse("4.023")) 0 0 0
102 {
103 0 CORE::return( [$class, $hash] );
104 }
105 }
106  
107 # But Storable wants a list with the first element being the serialised element
108 0 CORE::return( $class, $hash );
109 }
110  
111 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
112  
113 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
114  
115 sub STORABLE_thaw_post_processing
116 0 ▶{
Subroutine STORABLE_thaw_post_processing: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my $obj = shift( @_ );
118 0 my @keys = %$obj;
119 0 my $class = ref( $obj );
120 0 my $hash = {};
121 0 @$hash{ @keys } = @$obj{ @keys };
122 0 my $self = bless( $hash => $class );
123 0 return( $self );
124 }
125  
126 sub THAW
127 0 ▶{
Subroutine THAW: not called CC=10 SCAR=47.0
Pod undocumented
128 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
129 # 'CBOR' as the second value.
130 0 my( $self, undef, @args ) = @_;
131 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
132 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
133 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
134 0 my $new;
135 # Storable pattern requires to modify the object it created rather than returning a new one
136 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
137 {
138 0 foreach( CORE::keys( %$hash ) )
139 {
140 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
141 }
142 0 $new = $self;
143 }
144 else
145 {
146 0 $new = CORE::bless( $hash => $class );
147 }
148 0 CORE::return( $new );
149 }
150  
151 1 1;
152 # NOTE: POD
153 __END__
« lib/DB/Object/SQLite/Statement.pm ↑ Summary lib/DB/Object/Query/Elements.pm »