| 1 | package Magpie::Plugin::DBI; | ||||||||||||
| 2 | 2 | $Magpie::Plugin::DBI::VERSION = '1.163200'; | |||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | # ABSTRACT: A simple Role for dealing with DBI-backed assets; | ||||||||||||
| 6 | # | ||||||||||||
| 7 | 2 | ▶ | use Magpie::Constants; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | has dsn => ( | |||||||||||
| 10 | isa => "Str", | ||||||||||||
| 11 | is => "ro", | ||||||||||||
| 12 | predicate => "has_dsn", | ||||||||||||
| 13 | ); | ||||||||||||
| 14 | |||||||||||||
| 15 | 2 | has extra_args => ( | |||||||||||
| 16 | isa => "HashRef|ArrayRef", | ||||||||||||
| 17 | is => "ro", | ||||||||||||
| 18 | predicate => "has_extra_args", | ||||||||||||
| 19 | ); | ||||||||||||
| 20 | |||||||||||||
| 21 | 2 | has username => ( | |||||||||||
| 22 | is => 'ro', | ||||||||||||
| 23 | isa => 'Maybe[Str]', | ||||||||||||
| 24 | predicate => 'has_username', | ||||||||||||
| 25 | ); | ||||||||||||
| 26 | |||||||||||||
| 27 | 2 | has password => ( | |||||||||||
| 28 | is => 'ro', | ||||||||||||
| 29 | isa => 'Maybe[Str]', | ||||||||||||
| 30 | predicate => 'has_password', | ||||||||||||
| 31 | ); | ||||||||||||
| 32 | |||||||||||||
| 33 | 1 | ▶ | sub _connect_args { | ||||||||||
|
Subroutine
_connect_args: called CC=6 SCAR=20.5
| |||||||||||||
| 34 | 1 | my $self = shift; | |||||||||||
| 35 | 1 | ▶ | my @args = ( $self->dsn || die "dsn is required" ); | ||||||||||
|
Condition50%1/2
$self->dsn || die('dsn is required')
MC/DC0%0/1
$self->dsn || die('dsn is required')
$self->dsn
Truth table50%1/2
A
A= $self->dsn
| |||||||||||||
| 36 | |||||||||||||
| 37 | 1 | ▶ | if ( $self->has_username ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 0 | push @args, user => $self->username; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 1 | ▶ | if ( $self->has_password ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 0 | push @args, password => $self->password; | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 1 | ▶ | if ( $self->has_extra_args ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 1 | my $extra = $self->extra_args; | |||||||||||
| 47 | |||||||||||||
| 48 | 1 | ▶ | if ( ref($extra) eq 'ARRAY' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | push @args, @$extra; | |||||||||||
| 50 | } | ||||||||||||
| 51 | else { | ||||||||||||
| 52 | 1 | push @args, %$extra; | |||||||||||
| 53 | } | ||||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 1 | \@args; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | 2 | 1; | |||||||||||
| 61 | |||||||||||||
| 62 | __END__ | ||||||||||||