blib/lib/Teng/Schema.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 87.5% 7 / 8 totaltotal 96.0% 73 / 76 CC 4 SCAR 2.9
CC
4
Cov
96%
get_row_class
2.1
get_table
2.0
prepare_from_dbh
2.0
CRAP 1.3
« blib/lib/Teng/Schema/Declare.pm ↑ Summary Build »
1 package Teng::Schema;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Teng::Row;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use Class::Accessor::Lite
6 5 rw => [ qw(
7 tables
8 namespace
9 ) ]
10 5 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub new {
13 7 ▶ my ($class, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 7 bless {
15 tables => {},
16 namespace => '',
17 %args,
18 }, $class;
19 }
20  
21 sub set_default_instance {
22 3 ▶ my ($class, $instance) = @_;
Subroutine set_default_instance: called CC=1 SCAR=0.0
Pod documented
23 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ${"$class\::DEFAULT_INSTANCE"} = $instance;
26 }
27  
28 sub instance {
29 14 ▶ my $class = shift;
Subroutine instance: called CC=1 SCAR=0.0
Pod documented
30 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 14 ${"$class\::DEFAULT_INSTANCE"};
33 }
34  
35 sub add_table {
36 9 ▶ my ($self, $table) = @_;
Subroutine add_table: called CC=1 SCAR=0.0
Pod documented
37 9 $self->{tables}->{$table->name} = $table;
38 }
39  
40 sub get_table {
41 24 ▶ my ($self, $name) = @_;
Subroutine get_table: called CC=2 SCAR=6.9
Pod documented
42 24 ▶ return unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 23 24
43 23 $self->{tables}->{$name};
44 }
45  
46 sub get_row_class {
47 6 ▶ my ($self, $table_name) = @_;
Subroutine get_row_class: called CC=2 SCAR=7.6
Pod documented
48  
49 6 my $table = $self->{tables}->{$table_name};
50 6 ▶ return $table->{row_class} if $table;
Branch: 1 branch
BranchTrueFalseTotal
if $table 6 0 6
51 0 return 'Teng::Row';
52 }
53  
54 sub camelize {
55 9 ▶ my $s = shift;
Subroutine camelize: called CC=1 SCAR=0.0
Pod documented
56 9 join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s));
57 }
58  
59 sub prepare_from_dbh {
60 5 ▶ my ($self, $dbh) = @_;
Subroutine prepare_from_dbh: called CC=2 SCAR=6.9
Pod undocumented
61  
62 5 $_->prepare_from_dbh($dbh) for values %{$self->{tables}};
63 }
64  
65 5 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 default instance object, was set by C<< Teng::Schema->set_default_instance() >>.
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  
« blib/lib/Teng/Schema/Declare.pm ↑ Summary Build »