| 1 | package Egg::Model::DBIC; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # $Id: DBIC.pm 324 2008-04-17 12:45:09Z lushe $ | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '3.01'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub _setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my($class, $e)= @_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | Egg::Model::DBIC::handler->_setup($e); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | $class->next::method($e); | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | package Egg::Model::DBIC::handler; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use UNIVERSAL::require; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use base qw/ Egg::Model /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub _setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup: not called CC=17 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my($class, $e)= @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $dbic_path= $e->path_to(qw{ lib_project Model/DBIC }); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | -e $dbic_path || die __PACKAGE__. qq{ - '${dbic_path}'is not found. }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $schemas= $e->ixhash; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | no strict 'refs'; ## no critic. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | for (sort (grep /\.pm$/, <$dbic_path/*>)) { ## no critic. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | m{([^\\\/\:]+)\.pm$} || next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $pkg = $e->project_name. "::Model::DBIC::$1"; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $name= lc $1; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $pkg->require or die $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $c= $pkg->config || die __PACKAGE__. qq{ - '$pkg' config is empty. }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$pkg->config || die('Egg::Model::DBIC::handler' . " - '${pkg}' config is empty. ")
MC/DC0%0/1
$pkg->config || die('Egg::Model::DBIC::handler' . " - '${pkg}' config is empty. ")
$pkg->config
Truth table0%0/2
A
A= $pkg->config
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $c->{dsn} || die __PACKAGE__. q{ - '$pkg' dsn is empty. }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $c->{user} ||= ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->{"user"} ||= ""
MC/DC0%0/1
$c->{"user"} ||= ""
$c->{"user"}
Truth table0%0/2
A
A= $c->{"user"}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $c->{password} ||= ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->{"password"} ||= ""
MC/DC0%0/1
$c->{"password"} ||= ""
$c->{"password"}
Truth table0%0/2
A
A= $c->{"password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $c->{options} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->{"options"} ||= {}
MC/DC0%0/1
$c->{"options"} ||= {}
$c->{"options"}
Truth table0%0/2
A
A= $c->{"options"}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $label= lc( $c->{label_name} || "dbic::$name" ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->{'label_name'} || "dbic::$name"
MC/DC0%0/1
$c->{'label_name'} || "dbic::$name"
$c->{'label_name'}
Truth table0%0/2
A
A= $c->{'label_name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $alias= $c->{label_source} || $c->{label_moniker} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$c->{'label_source'} || $c->{'label_moniker'} || {}
$c->{"label_source"} or $c->{"label_moniker"}
MC/DC0%0/2
$c->{'label_source'} || $c->{'label_moniker'} || {}
$c->{"label_source"}
$c->{"label_moniker"}
Truth table0%0/3
A or B
A= $c->{"label_source"}B= $c->{"label_moniker"}
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $alias= { map{ lc($_) => $alias->{$_} }keys %$alias }; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $e->model_manager->add_register(0, $label, $pkg); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | *{"${pkg}::new"}= $class->_mk_schema_closure | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ($pkg, @{$c}{qw{ dsn user password options }}); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $schema= $pkg->new | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$pkg->new || die(" Schema of '${pkg}' cannot be connected. ")
MC/DC0%0/1
$pkg->new || die(" Schema of '${pkg}' cannot be connected. ")
$pkg->new
Truth table0%0/2
A
A= $pkg->new
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | || die qq{ Schema of '$pkg' cannot be connected. }; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | for my $moniker ($schema->sources) { | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $m_class= "${pkg}::$moniker"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $m_label= $alias->{lc $moniker} || "${label}::$moniker"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$alias{lc $moniker} || "${label}::$moniker"
MC/DC0%0/1
$$alias{lc $moniker} || "${label}::$moniker"
$$alias{lc $moniker}
Truth table0%0/2
A
A= $$alias{lc $moniker}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $e->model_manager->add_register(0, $m_label, $m_class); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | *{"${m_class}::ACCEPT_CONTEXT"}= | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub { $_[1]->model($label)->resultset($moniker) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $schemas->{$label}= $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | %$schemas or die __PACKAGE__. q{ - Schema module is not found. }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $e->global->{dbic_schemas}= $schemas; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _mk_schema_closure { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_schema_closure: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my($class, $s_class, @source)= @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $schema; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | return $schema if ( $schema | ||||||||||||||||||||||||||||||||||||||||||
| 67 | and $schema->storage->dbh->{Active} | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | and $schema->storage->dbh->ping | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$schema and $schema->storage->dbh->{"Active"} and $schema->storage->dbh->ping
$schema and $schema->storage->dbh->{"Active"}
MC/DC0%0/3
$schema and $schema->storage->dbh->{"Active"} and $schema->storage->dbh->ping
$schema
$schema->storage->dbh->{"Active"}
$schema->storage->dbh->ping
Truth table0%0/4
A and B and C
A= $schemaB= $schema->storage->dbh->{"Active"}C= $schema->storage->dbh->ping
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $schema= $s_class->connect(@source); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||||||||||||||||