Teng/Schema/Table.pm

filter: Statementstmt 39.5% 32 / 81 Branchbran 5.0% 1 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 8 / 16 Podpod 66.6% 6 / 9 totaltotal 36.4% 47 / 129 CC 13 SCAR 18.9
CC
13
Cov
32%
add_deflator
12.0
add_inflator
12.0
call_deflate
12.0
CRAP 6.6
« Teng/Schema/Dumper.pm ↑ Summary Teng/Schema/Loader.pm »
1 package Teng::Schema::Table;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 use Class::Accessor::Lite
5 1 rw => [ qw(
6 name
7 primary_keys
8 columns
9 escaped_columns
10 sql_types
11 row_class
12 ) ]
13 1 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Class::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub new {
18 1 ▶ my ($class, %args) = @_;
Subroutine new: called CC=4 SCAR=14.5
Pod documented
19 1 my $self = bless {
20 deflators => [],
21 inflators => [],
22 escaped_columns => {},
23 %args
24 }, $class;
25  
26 # load row class
27 1 my $row_class = $self->row_class;
28 1 ▶ Class::Load::load_optional_class($row_class) or do {
Branch: 1 branch
BranchTrueFalseTotal
Class::Load::load_optional_class($row_class) or do { no strict 'refs'; @{"${row_class}::ISA";} = "Teng::Row" } 1 0 1
29 # make row class automatically
30 1 ▶ no strict 'refs'; @{"$row_class\::ISA"} = ('Teng::Row');
Subroutine BEGIN: called CC=1 SCAR=0.0
31 };
32 1 for my $col (@{$self->columns}) {
33 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 0 ▶ unless ($row_class->can($col)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($row_class->can($col)) 0 0 0
35 0 *{"$row_class\::$col"} = $row_class->_lazy_get_data($col);
36 }
37 }
38 1 $self->row_class($row_class);
39  
40 1 return $self;
41 }
42  
43 sub get_sql_type {
44 0 ▶ my ($self, $column_name) = @_;
Subroutine get_sql_type: not called CC=1 SCAR=6.9
Pod documented
45 0 $self->sql_types->{ $column_name };
46 }
47  
48 sub add_deflator {
49 0 ▶ my ($self, $rule, $code) = @_;
Subroutine add_deflator: not called CC=3 SCAR=24.8
Pod undocumented
50 0 ▶ if ( ref $rule ne 'Regexp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rule ne "Regexp") 0 0 0
51 0 $rule = qr/^\Q$rule\E$/;
52 }
53 0 ▶ unless (ref($code) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $code eq "CODE") 0 0 0
54 0 Carp::croak('deflate code must be coderef.');
55 }
56 0 push @{ $self->{deflators} }, ( $rule, $code );
57 }
58  
59 sub add_inflator {
60 0 ▶ my ($self, $rule, $code) = @_;
Subroutine add_inflator: not called CC=3 SCAR=24.8
Pod undocumented
61 0 ▶ if ( ref $rule ne 'Regexp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rule ne "Regexp") 0 0 0
62 0 $rule = qr/^\Q$rule\E$/;
63 }
64 0 ▶ unless (ref($code) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $code eq "CODE") 0 0 0
65 0 Carp::croak('inflate code must be coderef.');
66 }
67 0 push @{ $self->{inflators} }, ( $rule, $code );
68 }
69  
70 sub call_deflate {
71 0 ▶ my ($self, $col_name, $col_value) = @_;
Subroutine call_deflate: not called CC=3 SCAR=24.8
Pod documented
72 0 my $rules = $self->{deflators};
73 0 my $i = 0;
74 0 my $max = @$rules;
75 0 ▶ while ( $i < $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max) 0 0 0
76 0 my ($rule, $code) = @$rules[ $i, $i + 1 ];
77 0 ▶ if ($col_name =~ /$rule/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col_name =~ /$rule/) 0 0 0
78 0 return $code->($col_value);
79 }
80 0 $i += 2;
81 }
82 0 return $col_value;
83 }
84  
85 sub call_inflate {
86 0 ▶ my ($self, $col_name, $col_value) = @_;
Subroutine call_inflate: not called CC=3 SCAR=24.8
Pod documented
87 0 my $rules = $self->{inflators};
88 0 my $i = 0;
89 0 my $max = @$rules;
90 0 ▶ while ( $i < $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max) 0 0 0
91 0 my ($rule, $code) = @$rules[ $i, $i + 1 ];
92 0 ▶ if ($col_name =~ /$rule/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col_name =~ /$rule/) 0 0 0
93 0 return $code->($col_value);
94 }
95 0 $i += 2;
96 }
97 0 return $col_value;
98 }
99  
100 sub has_deflators {
101 0 ▶ my $self = shift;
Subroutine has_deflators: not called CC=1 SCAR=6.9
Pod documented
102 0 return scalar @{ $self->{deflators} };
103 }
104  
105 sub has_inflators {
106 0 ▶ my $self = shift;
Subroutine has_inflators: not called CC=1 SCAR=6.9
Pod documented
107 0 return scalar @{ $self->{inflators} };
108 }
109  
110 sub prepare_from_dbh {
111 0 ▶ my ($self, $dbh) = @_;
Subroutine prepare_from_dbh: not called CC=2 SCAR=17.9
Pod undocumented
112  
113 $self->escaped_columns->{$dbh->{Driver}->{Name}} ||= [
114 0 map { \$dbh->quote_identifier($_) }
115 0 ▶ @{$self->columns}
Condition0%0/2
$self->escaped_columns->{$dbh->{"Driver"}{"Name"}} ||= [map({\$dbh->quote_identifier($_);} @{$self->columns;})]
l!l
00
MC/DC0%0/1
$self->escaped_columns->{$dbh->{"Driver"}{"Name"}} ||= [map({\$dbh->quote_identifier($_);} @{$self->columns;})]
$self->escaped_columns->{$dbh->{"Driver"}{"Name"}}
Truth table0%0/2
A
A= $self->escaped_columns->{$dbh->{"Driver"}{"Name"}}
Aresult
11
00
116 ];
117 }
118  
119 1 1;
120  
121 __END__
122  
123 =head1 NAME
124  
125 Teng::Schema::Table - Teng table class.
126  
127 =head1 METHODS
128  
129 =over 4
130  
131 =item $table = Teng::Schema::Table->new
132  
133 create new Teng::Schema::Table's object.
134  
135 =item $table->get_sql_type
136  
137 get column SQL type.
138  
139 =item $table->get_deflator
140  
141 get deflate coderef.
142  
143 =item $table->get_inflator
144  
145 get inflate coderef.
146  
147 =item $table->set_deflator
148  
149 set deflate coderef.
150  
151 =item $table->set_inflator
152  
153 set inflate coderef.
154  
155 =item $table->call_deflate
156  
157 execute deflate.
158  
159 =item $table->call_inflate
160  
161 execute inflate.
162  
163 =item $table->has_deflators()
164  
165 Returns true if there are any deflators
166  
167 =item $table->has_inflators();
168  
169 Returns true if there are any inflators
170  
171 =back
« Teng/Schema/Dumper.pm ↑ Summary Teng/Schema/Loader.pm »