Drupal.pm

filter: Statementstmt 97.7% 43 / 44 Branchbran 61.1% 11 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 84.4% 65 / 77 SCAR 25.3
CC
12
Cov
85%
dbh
14.4
BEGIN
1.0
BEGIN
1.0
CRAP 12.5
« Drupal/Admin/MaintenanceMode.pm ↑ Summary Drupal/Types.pm »
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
BranchTrueFalseTotal
if defined $self->{"_dbh"} 0 13 13
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
BranchTrueFalseTotal
exists $ENV{'DRUPAL_TEST_CREDS'} && !exists $ENV{'DRUPAL_IGNORE_TEST_CREDS'} ? : 0 13 13
Condition33%1/3
exists $ENV{"DRUPAL_TEST_CREDS"} and not exists $ENV{"DRUPAL_IGNORE_TEST_CREDS"}
!ll&&!rl&&r
1300
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"}
ABresult
0X0
100
111
24 { @_ };
25  
26 13 ▶ confess "Fatal error! No database name provided! " unless exists $args->{'database'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"database"} 1 12 13
27 12 ▶ confess "Fatal error! No dbi:driver provided! " unless exists $args->{'driver'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"driver"} 1 11 12
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
BranchTrueFalseTotal
unless exists $types{$_} 0 18 18
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
BranchTrueFalseTotal
exists $args->{"host"} and $dsn .= qq[;host=$args->{"host"}] 0 1 1
47 1 ▶ exists $args->{'port'} and $dsn .= ";port=$args->{'port'}";
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"port"} and $dsn .= qq[;port=$args->{"port"}] 0 1 1
48 1 ▶ my $username = exists $args->{'username'} ? $args->{'username'} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'username'} ? : 0 1 1
49 1 ▶ my $password = exists $args->{'password'} ? $args->{'password'} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'password'} ? : 0 1 1
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__
« Drupal/Admin/MaintenanceMode.pm ↑ Summary Drupal/Types.pm »