File Coverage

blib/lib/CMS/Drupal.pm
Criterion Covered Total %
statement 38 45 84.4
branch 6 16 37.5
condition n/a
subroutine 10 10 100.0
pod 1 1 100.0
total 55 72 76.3


line stmt bran cond sub pod time code
1             package CMS::Drupal;
2             $CMS::Drupal::VERSION = '0.090';
3             # ABSTRACT: Perl interface to the Drupal CMS
4              
5 2     2   1796 use strict;
  2         3  
  2         69  
6 2     2   8 use warnings;
  2         2  
  2         49  
7 2     2   35 use 5.010;
  2         4  
  2         51  
8              
9 2     2   1149 use Moo;
  2         29738  
  2         14  
10 2     2   7205 use Types::Standard qw/ Optional Maybe Str Int slurpy Dict /;
  2         117937  
  2         22  
11 2     2   3248 use CMS::Drupal::Types qw/ DBName DBDriver DBUsername DBPassword DBHost DBPort DBPrefix /;
  2         6  
  2         21  
12 2     2   2935 use Type::Params qw/ compile /;
  2         20944  
  2         22  
13              
14 2     2   3521 use DBI;
  2         47531  
  2         164  
15 2     2   18 use Carp qw/ confess croak /;
  2         5  
  2         714  
16              
17             sub dbh {
18 14     14 1 11477 my $self = shift;
19 14 50       48 return $self->{'_dbh'} if defined( $self->{'_dbh'} );
20              
21 14         39 my $args = { @_ };
22              
23 14 100       186 confess "Fatal error! No database name provided! " unless exists $args->{'database'};
24 13 100       1049 confess "Fatal error! No dbi:driver provided! " unless exists $args->{'driver'};
25              
26 4         17 my %types = (
27             database => DBName,
28             driver => DBDriver,
29             username => DBUsername,
30             password => DBPassword,
31             host => DBHost,
32             port => DBPort,
33             prefix => DBPrefix,
34             );
35              
36 4         104 for ( keys %{$args} ) {
  4         15  
37 7 50       154 next unless exists $types{ $_ }; # throw away unknown params
38 7         26 my $validate = compile( slurpy Dict [ $_ => $types{$_} ]);
39 7         37391 my ($param) = $validate->( $_ => $args->{$_} );
40             }
41              
42 0           my $dsn = join(':', 'dbi', $args->{'driver'}, $args->{'database'});
43 0 0         exists $args->{'host'} and $dsn .= (';host=' . $args->{'host'});
44 0 0         exists $args->{'port'} and $dsn .= (';port=' . $args->{'port'});
45 0 0         my $username = (exists $args->{'username'} ? $args->{'username'} : '');
46 0 0         my $password = (exists $args->{'password'} ? $args->{'password'} : '');
47 0           $self->{'_dbh'} = DBI->connect( $dsn, $username, $password, { 'RaiseError' => 1 } );
48              
49 0           return $self->{'_dbh'};
50             }
51              
52             1; ## return true to end package CMS::Drupal
53             __END__