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.091';
3             # ABSTRACT: Perl interface to the Drupal CMS
4              
5 2     2   31504 use strict;
  2         5  
  2         84  
6 2     2   7 use warnings;
  2         3  
  2         52  
7 2     2   38 use 5.010;
  2         8  
  2         60  
8              
9 2     2   923 use Moo;
  2         47705  
  2         11  
10 2     2   4445 use Types::Standard qw/ Optional Maybe Str Int slurpy Dict /;
  2         139691  
  2         31  
11 2     2   4467 use CMS::Drupal::Types qw/ DBName DBDriver DBUsername DBPassword DBHost DBPort DBPrefix /;
  2         5  
  2         31  
12 2     2   3562 use Type::Params qw/ compile /;
  2         26139  
  2         20  
13              
14 2     2   3923 use DBI;
  2         32454  
  2         131  
15 2     2   17 use Carp qw/ confess croak /;
  2         3  
  2         702  
16              
17             sub dbh {
18 14     14 1 16388 my $self = shift;
19 14 50       53 return $self->{'_dbh'} if defined( $self->{'_dbh'} );
20              
21 14         50 my $args = { @_ };
22              
23 14 100       186 confess "Fatal error! No database name provided! " unless exists $args->{'database'};
24 13 100       177 confess "Fatal error! No dbi:driver provided! " unless exists $args->{'driver'};
25              
26 12         48 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 12         305 for ( keys %{$args} ) {
  12         53  
37 20 50       612 next unless exists $types{ $_ }; # throw away unknown params
38 20         93 my $validate = compile( slurpy Dict [ $_ => $types{$_} ]);
39 20         100353 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__