blib/lib/DB/Object/Constraint/Check.pm untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 149 CC 8 SCAR 23.5
CC
8
Cov
0%
THAW
30.0
FREEZE
20.0
BEGIN
2.0
CRAP 10.5
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 ## 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::Constraint::Check;
14 BEGIN
15 {
16 use strict;
17 use warnings;
18 warnings::register_categories( 'DB::Object' );
19 use parent qw( Module::Generic );
20 use vars qw( $VERSION $EXCEPTION_CLASS );
21 our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
22 our $VERSION = 'v0.2.0';
23 };
24  
25 use strict;
26 use warnings;
27  
28 sub init
29 {
30 my $self = shift( @_ );
31 $self->{expr} = undef;
32 $self->{fields} = undef;
33 $self->{name} = undef;
34 $self->{_init_strict_use_sub} = 1;
35 $self->{_exception_class} = $EXCEPTION_CLASS;
36 $self->SUPER::init( @_ ) || return( $self->pass_error );
37 return( $self );
38 }
39  
40 sub expr { return( shift->_set_get_scalar_as_object( 'expr', @_ ) ); }
41  
42 sub fields { return( shift->_set_get_array_as_object( 'fields', @_ ) ); }
43  
44 sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
45  
46 # NOTE: For CBOR and Sereal
47 sub FREEZE
48 {
49 my $self = CORE::shift( @_ );
50 my $serialiser = CORE::shift( @_ ) // '';
51 my $class = CORE::ref( $self );
52  
53 my @props = qw(
54 expr fields name
55 );
56  
57 my $hash = {};
58 foreach my $prop ( @props )
59 {
60 if( CORE::exists( $self->{ $prop } ) &&
61 defined( $self->{ $prop } ) &&
62 CORE::ref( $self->{ $prop } ) ne 'CODE' )
63 {
64 $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 if( $serialiser eq 'Sereal' )
71 {
72 require Sereal::Encoder;
73 require version;
74  
75 if( version->parse( Sereal::Encoder->VERSION ) < version->parse( '4.023' ) )
76 {
77 CORE::return( [$class, $hash] );
78 }
79 }
80  
81 # But Storable wants a list with the first element being the serialised element
82 CORE::return( $class, $hash );
83 }
84  
85 sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
86  
87 sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
88  
89 sub STORABLE_thaw_post_processing
90 {
91 my $obj = shift( @_ );
92 my @keys = %$obj;
93 my $class = ref( $obj );
94 my $hash = {};
95 @$hash{ @keys } = @$obj{ @keys };
96 my $self = bless( $hash => $class );
97 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 my( $self, undef, @args ) = @_;
105 my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
106 my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
107 my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
108 my $new;
109 # Storable pattern requires to modify the object it created rather than returning a new one
110 if( CORE::ref( $self ) )
111 {
112 foreach( CORE::keys( %$hash ) )
113 {
114 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
115 }
116 $new = $self;
117 }
118 else
119 {
120 $new = CORE::bless( $hash => $class );
121 }
122 CORE::return( $new );
123 }
124  
125 1;
126 # NOTE: POD
127 __END__