| 1 | package CMS::Drupal; | ||||||||||||||||||||||||||||
| 2 | 3 | $CMS::Drupal::VERSION = '0.94'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Perl interface to the Drupal CMS | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Types::Standard qw/ Optional Maybe Str Int slurpy Dict /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use CMS::Drupal::Types qw/ DBName DBDriver DBUsername DBPassword DBHost DBPort DBPrefix /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Type::Params qw/ compile /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Carp qw/ confess croak /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub dbh { | ||||||||||||||||||||||||||||
| 17 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
dbh: called CC=12 SCAR=26.7
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 13 | ▶ | return $self->{'_dbh'} if defined( $self->{'_dbh'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # We want to accept no params if we have the values in the env. But | ||||||||||||||||||||||||||||
| 21 | # we don't want to use those creds when we are running certain tests | ||||||||||||||||||||||||||||
| 22 | my $args = (exists $ENV{'DRUPAL_TEST_CREDS'} and ! exists $ENV{'DRUPAL_IGNORE_TEST_CREDS'}) ? | ||||||||||||||||||||||||||||
| 23 | 13 | ▶ | { split(',', $ENV{'DRUPAL_TEST_CREDS'}) } : | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $ENV{"DRUPAL_TEST_CREDS"} and not exists $ENV{"DRUPAL_IGNORE_TEST_CREDS"}
MC/DC0%0/2
exists $ENV{"DRUPAL_TEST_CREDS"} and not exists $ENV{"DRUPAL_IGNORE_TEST_CREDS"}
exists $ENV{"DRUPAL_TEST_CREDS"}
not exists $ENV{"DRUPAL_IGNORE_TEST_CREDS"}
Truth table33%1/3
A and not(B)
A= exists $ENV{"DRUPAL_TEST_CREDS"}B= not exists $ENV{"DRUPAL_IGNORE_TEST_CREDS"}
| |||||||||||||||||||||||||||||
| 24 | { @_ }; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 13 | ▶ | confess "Fatal error! No database name provided! " unless exists $args->{'database'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 12 | ▶ | confess "Fatal error! No dbi:driver provided! " unless exists $args->{'driver'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 11 | my %types = ( | |||||||||||||||||||||||||||
| 30 | 'database' => DBName, | ||||||||||||||||||||||||||||
| 31 | 'driver' => DBDriver, | ||||||||||||||||||||||||||||
| 32 | 'username' => DBUsername, | ||||||||||||||||||||||||||||
| 33 | 'password' => DBPassword, | ||||||||||||||||||||||||||||
| 34 | 'host' => DBHost, | ||||||||||||||||||||||||||||
| 35 | 'port' => DBPort, | ||||||||||||||||||||||||||||
| 36 | 'prefix' => DBPrefix, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 11 | for ( keys %{ $args } ) { | |||||||||||||||||||||||||||
| 40 | 18 | ▶ | next unless exists $types{ $_ }; # throw away unknown params | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 18 | my $validate = compile( slurpy Dict [ $_ => $types{ $_ } ]); | |||||||||||||||||||||||||||
| 42 | 18 | my ( $param ) = $validate->( $_ => $args->{ $_ } ); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | my $dsn = join( ':', 'dbi', $args->{'driver'}, $args->{'database'} ); | |||||||||||||||||||||||||||
| 46 | 1 | ▶ | exists $args->{'host'} and $dsn .= ";host=$args->{'host'}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | exists $args->{'port'} and $dsn .= ";port=$args->{'port'}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | my $username = exists $args->{'username'} ? $args->{'username'} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | my $password = exists $args->{'password'} ? $args->{'password'} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 1 | $self->{'_dbh'} = DBI->connect( $dsn, $username, $password, { 'RaiseError' => 1 } ); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return $self->{'_dbh'}; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 3 | 1; ## return true to end package CMS::Drupal | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||