blib/lib/Teng/Schema/Table.pm

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