Teng/Schema.pm

filter: Statementstmt 85.4% 41 / 48 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 14 / 16 Podpod 87.5% 7 / 8 totaltotal 84.2% 64 / 76 CC 4 SCAR 7.7
CC
4
Cov
83%
get_row_class
6.0
prepare_from_dbh
6.0
get_table
2.0
CRAP 2.2
« Teng/Plugin/Pager/MySQLFoundRows.pm ↑ Summary Teng/Plugin/Count.pm »
1 package Teng::Schema;
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 1 ▶use Teng::Row;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use Class::Accessor::Lite
6 1 rw => [ qw(
7 tables
8 namespace
9 ) ]
10 1 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub new {
13 1 ▶ my ($class, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 1 bless {
15 tables => {},
16 namespace => '',
17 %args,
18 }, $class;
19 }
20  
21 sub set_default_instance {
22 1 ▶ my ($class, $instance) = @_;
Subroutine set_default_instance: called CC=1 SCAR=0.0
Pod documented
23 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ${"$class\::DEFAULT_INSTANCE"} = $instance;
26 }
27  
28 sub instance {
29 2 ▶ my $class = shift;
Subroutine instance: called CC=1 SCAR=0.0
Pod documented
30 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ${"$class\::DEFAULT_INSTANCE"};
33 }
34  
35 sub add_table {
36 1 ▶ my ($self, $table) = @_;
Subroutine add_table: called CC=1 SCAR=0.0
Pod documented
37 1 $self->{tables}->{$table->name} = $table;
38 }
39  
40 sub get_table {
41 2 ▶ my ($self, $name) = @_;
Subroutine get_table: called CC=2 SCAR=6.9
Pod documented
42 2 ▶ return unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
43 1 $self->{tables}->{$name};
44 }
45  
46 sub get_row_class {
47 0 ▶ my ($self, $table_name) = @_;
Subroutine get_row_class: not called CC=2 SCAR=17.9
Pod documented
48  
49 0 my $table = $self->{tables}->{$table_name};
50 0 ▶ return $table->{row_class} if $table;
Branch: 1 branch
BranchTrueFalseTotal
if $table 0 0 0
51 0 return 'Teng::Row';
52 }
53  
54 sub camelize {
55 1 ▶ my $s = shift;
Subroutine camelize: called CC=1 SCAR=0.0
Pod documented
56 1 join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s));
57 }
58  
59 sub prepare_from_dbh {
60 0 ▶ my ($self, $dbh) = @_;
Subroutine prepare_from_dbh: not called CC=2 SCAR=17.9
Pod undocumented
61  
62 0 $_->prepare_from_dbh($dbh) for values %{$self->{tables}};
63 }
64  
65 1 1;
66  
67 __END__
68  
69 =head1 NAME
70  
71 Teng::Schema - Schema API for Teng
72  
73 =head1 METHODS
74  
75 =over 4
76  
77 =item $schema = Teng::Schema->new
78  
79 create new Teng::Schema's object.
80  
81 =item $schema = Teng::Schema->instance
82  
83 get Teng::Schema's instance object.
84  
85 =item Teng::Schema->set_default_instance($schema)
86  
87 set default Schema instance.
88  
89 =item $schema->add_table($table);
90  
91 add Teng::Schema::Table's object.
92  
93 =item my $table = $schema->get_table($table_name);
94  
95 get Teng::Schema::Table's object.
96  
97 =item my $row_class = $schema->get_row_class($table_name);
98  
99 get your table row class or Teng::Row class.
100  
101 =item $schema->camelize($string)
102  
103 convert from under_score text to CamelCase one.
104  
105 =back
106  
107 =cut
108  
« Teng/Plugin/Pager/MySQLFoundRows.pm ↑ Summary Teng/Plugin/Count.pm »