| 1 | package DBIx::Factory; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Scalar::Util qw/ blessed /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Config::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = "0.09"; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | has "config_base" => ( | ||||||||||||||||||||||||||||
| 13 | is => "ro", | ||||||||||||||||||||||||||||
| 14 | isa => "Str", | ||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||
| 16 | 13 | ▶ | default => sub { defined $ENV{DBIF_BASE} ? $ENV{DBIF_BASE} : q{} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 3 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | has "config_file" => ( | |||||||||||||||||||||||||||
| 20 | is => "rw", | ||||||||||||||||||||||||||||
| 21 | isa => "Str", | ||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||
| 23 | default => q{}, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 19 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | 19 | my ($next_method, $class, @args) = @_; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 19 | ▶ | $class->$next_method( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | _isa_str(@args) ? ( config_base => $args[0] ) : @args | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | 3 | }; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 19 | ▶ | sub get_dbh { | ||||||||||||||||||||||||||
|
Subroutine
get_dbh: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 19 | my ($class_or_self, @args) = @_; | |||||||||||||||||||||||||||
| 36 | 19 | my $self; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 19 | ▶ | if ( blessed $class_or_self ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 7 | $self = $class_or_self; | |||||||||||||||||||||||||||
| 40 | 7 | ▶ | $self->config_file( $args[0] ) if _isa_str(@args); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||
| 43 | 12 | ▶ | $self = $class_or_self->new( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | _isa_str(@args) ? ( config_file => $args[0] ) : | ||||||||||||||||||||||||||||
| 45 | _has_odd_elm(@args) ? ( @args, undef ) : @args | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 19 | ▶ | $self->_get_dbh( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 50 | _is_empty($self->config_file) ? | ||||||||||||||||||||||||||||
| 51 | ( ref $args[0] ? $args[0] : [@args] ) : $self->_get_config | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 13 | ▶ | sub _get_config { | ||||||||||||||||||||||||||
|
Subroutine
_get_config: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 56 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 13 | my ($file, $dir) = ($self->config_file, $self->config_base); | |||||||||||||||||||||||||||
| 59 | 13 | ▶ | my $path | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_is_abs_path($file) or _is_empty($dir)
MC/DC100%2/2
_is_abs_path($file) or _is_empty($dir)
_is_abs_path($file)
_is_empty($dir)
Truth table100%3/3
A or B
A= _is_abs_path($file)B= _is_empty($dir)
| |||||||||||||||||||||||||||||
| 60 | = ( _is_abs_path($file) or _is_empty($dir) ) ? $file : | ||||||||||||||||||||||||||||
| 61 | join "/", $dir, $file ; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Config::Any->load_files( | ||||||||||||||||||||||||||||
| 64 | { files => [$path], use_ext => 1, flatten_to_hash => 1 } | ||||||||||||||||||||||||||||
| 65 | 13 | ▶ | )->{$path} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | or confess "failed to read config file: $path\n"; | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 17 | ▶ | sub _get_dbh { | ||||||||||||||||||||||||||
|
Subroutine
_get_dbh: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 70 | 17 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | DBI->connect( | ||||||||||||||||||||||||||||
| 73 | 17 | ▶ | _isa_hashref($args) ? @$args{qw/ dsn userid passwd attr /} : @$args | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 38 | ▶ | sub _isa_str { @_ == 1 and not ref $_[0] } | ||||||||||||||||||||||||||
|
Subroutine
_isa_str: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 17 | ▶ | sub _isa_hashref { ref $_[0] eq "HASH" } | ||||||||||||||||||||||||||
|
Subroutine
_isa_hashref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 13 | ▶ | sub _is_abs_path { File::Spec->file_name_is_absolute($_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
_is_abs_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 28 | ▶ | sub _is_empty { $_[0] eq q{} } | ||||||||||||||||||||||||||
|
Subroutine
_is_empty: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 11 | ▶ | sub _has_odd_elm { @_ % 2 } | ||||||||||||||||||||||||||
|
Subroutine
_has_odd_elm: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | 1; # End of DBIx::Factory | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||