lib/DB/Object/Constraint/Check.pm

filter: Statementstmt 31.8% 21 / 66 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 43.7% 7 / 16 Podpod 44.4% 4 / 9 totaltotal 23.1% 32 / 138 CC 18 SCAR 39.5
CC
18
Cov
21%
THAW
110.0
FREEZE
72.0
init
6.0
CRAP 51.7
« blib/lib/DB/Object/Mysql/Statement.pm ↑ Summary lib/DB/Object/Constraint/Index.pm »
1 ##----------------------------------------------------------------------------
2 ## Database Object Interface - ~/lib/DB/Object/Constraint/Check.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2023/11/20
7 ## Modified 2026/03/22
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package DB::Object::Constraint::Check;
15 BEGIN
16 {
17 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ▶ our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 our $VERSION = 'v0.2.0';
23 };
24  
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub init
29 {
30 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
31 0 $self->{expr} = undef;
32 0 $self->{fields} = undef;
33 0 $self->{name} = undef;
34 0 $self->{_init_strict_use_sub} = 1;
35 0 $self->{_exception_class} = $EXCEPTION_CLASS;
36 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
37 0 return( $self );
38 }
39  
40 0 ▶sub expr { return( shift->_set_get_scalar_as_object( 'expr', @_ ) ); }
Subroutine expr: not called CC=1 SCAR=6.9
Pod documented
41  
42 0 ▶sub fields { return( shift->_set_get_array_as_object( 'fields', @_ ) ); }
Subroutine fields: not called CC=1 SCAR=6.9
Pod documented
43  
44 0 ▶sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
45  
46 # NOTE: For CBOR and Sereal
47 sub FREEZE
48 {
49 0 ▶ my $self = CORE::shift( @_ );
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
50 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
51 0 my $class = CORE::ref( $self );
52  
53 0 my @props = qw(
54 expr fields name
55 );
56  
57 0 my $hash = {};
58 0 foreach my $prop ( @props )
59 {
60 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
61 defined( $self->{ $prop } ) &&
62 CORE::ref( $self->{ $prop } ) ne 'CODE' )
63 {
64 0 $hash->{ $prop } = $self->{ $prop };
65 }
66 }
67  
68 # Return an array reference rather than a list so this works with Sereal and CBOR.
69 # Before Sereal version 4.023, Sereal did not support multiple values returned.
70 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
71 {
72 0 require Sereal::Encoder;
73 0 require version;
74  
75 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
76 {
77 0 CORE::return( [$class, $hash] );
78 }
79 }
80  
81 # But Storable wants a list with the first element being the serialised element
82 0 CORE::return( $class, $hash );
83 }
84  
85 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
86  
87 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
88  
89 sub STORABLE_thaw_post_processing
90 {
91 0 ▶ my $obj = shift( @_ );
Subroutine STORABLE_thaw_post_processing: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my @keys = %$obj;
93 0 my $class = ref( $obj );
94 0 my $hash = {};
95 0 @$hash{ @keys } = @$obj{ @keys };
96 0 my $self = bless( $hash => $class );
97 0 return( $self );
98 }
99  
100 sub THAW
101 {
102 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
103 # 'CBOR' as the second value.
104 0 ▶ my( $self, undef, @args ) = @_;
Subroutine THAW: not called CC=10 SCAR=47.0
Pod undocumented
105 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
106 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
107 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
108 0 my $new;
109 # Storable pattern requires to modify the object it created rather than returning a new one
110 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
111 {
112 0 foreach( CORE::keys( %$hash ) )
113 {
114 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
115 }
116 0 $new = $self;
117 }
118 else
119 {
120 0 $new = CORE::bless( $hash => $class );
121 }
122 0 CORE::return( $new );
123 }
124  
125 1 1;
126 # NOTE: POD
127 __END__
128  
129 =encoding utf-8
130  
131 =head1 NAME
132  
133 DB::Object::Constraint::Check - Table Check Constraint Class
134  
135 =head1 SYNOPSIS
136  
137 use DB::Object::Constraint::Check;
138 my $check = DB::Object::Constraint::Check->new(
139 expr => q{CHECK (status::text ~* '^(active|inactive|locked|pending|protected|removed|suspended)$'::text)},
140 fields => [qw( status )],
141 name => 'chk_users_status',
142 ) || die( DB::Object::Constraint::Check->error, "\n" );
143  
144 =head1 VERSION
145  
146 v0.2.0
147  
148 =head1 DESCRIPTION
149  
150 This class represents a table check constraint. It is instantiated by the L<structure|DB::Object::Tables/structure> method when retrieving the table structure details.
151  
152 =head1 CONSTRUCTOR
153  
154 =head2 new
155  
156 To instantiate new object, you can pass an hash or hash reference of properties matching the method names available below.
157  
158 =head1 METHODS
159  
160 =head2 expr
161  
162 Sets or gets a check constraint expression.
163  
164 It returns a L<scalar object|Module::Generic::Scalar>
165  
166 =head2 fields
167  
168 Sets or gets an array reference of table field names associated with this constraint.
169  
170 It returns a L<array object|Module::Generic::Array>
171  
172 =head2 name
173  
174 Sets or gets the check constraint name.
175  
176 It returns a L<scalar object|Module::Generic::Scalar>
177  
178 =head1 AUTHOR
179  
180 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
181  
182 =head1 SEE ALSO
183  
184 L<perl>
185  
186 =head1 COPYRIGHT & LICENSE
187  
188 Copyright(c) 2023 DEGUEST Pte. Ltd.
189  
190 All rights reserved
191  
192 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
193  
194 =cut
« blib/lib/DB/Object/Mysql/Statement.pm ↑ Summary lib/DB/Object/Constraint/Index.pm »