File Coverage

blib/lib/Geoffrey/Role/Core.pm
Criterion Covered Total %
statement 38 39 97.4
branch 7 10 70.0
condition 11 15 73.3
subroutine 12 13 92.3
pod 9 9 100.0
total 77 86 89.5


line stmt bran cond sub pod time code
1             package Geoffrey::Role::Core;
2              
3 7     7   5252 use utf8;
  7         16  
  7         44  
4 7     7   362 use 5.016;
  7         26  
5 7     7   41 use strict;
  7         16  
  7         177  
6 7     7   76 use warnings;
  7         39  
  7         4858  
7              
8             $Geoffrey::Role::Core::VERSION = '0.000206';
9              
10             sub new {
11 18     18 1 5288 my $class = shift;
12 18         89 my $self = {@_};
13              
14             # make dbh required
15 18 100       73 if (!$self->{dbh}) {
16 4         24 require Geoffrey::Exception::Database;
17 4         15 Geoffrey::Exception::Database::throw_no_dbh();
18             }
19              
20             # be sure thet dbh is realy a DBI::db object or a test DBI
21 14 100 100     126 if (!$self->{dbh}->isa('DBI::db') && !$self->{dbh}->isa('Test::Mock::Geoffrey::DBI')) {
22 1         5 require Geoffrey::Exception::Database;
23 1         4 Geoffrey::Exception::Database::throw_not_dbh();
24             }
25 13         60 return bless $self, $class;
26             }
27              
28             sub converter_name {
29 3   100 3 1 17 $_[0]->{converter_name} //= 'SQLite';
30 3         11 return $_[0]->{converter_name};
31             }
32              
33             sub io_name {
34 8   100 8 1 43 $_[0]->{io_name} //= 'None';
35 8         37 return $_[0]->{io_name};
36             }
37 92     92 1 795 sub dbh { return $_[0]->{dbh} }
38 12     12 1 72 sub schema { return $_[0]->{schema} }
39 0   0 0 1 0 sub environment_system { return $_[0]->{system} // 'main'; }
40 1     1 1 2456 sub disconnect { return $_[0]->{dbh}->disconnect; }
41              
42             sub converter {
43 99     99 1 236 my ($self) = @_;
44 99         3726 require Geoffrey::Utils;
45 99   66     411 $self->{converter} //= Geoffrey::Utils::converter_obj_from_name($self->converter_name);
46 99         758 return $self->{converter};
47             }
48              
49             sub changelog_io {
50 11     11 1 130 my ($self) = @_;
51 11         93 require Geoffrey::Utils;
52 11   66     69 $self->{changelog_io} //= Geoffrey::Utils::changelog_io_from_name($self->io_name);
53 11 50       102 $self->{changelog_io}->converter($self->converter) if $self->{changelog_io}->needs_converter;
54 11 50       45 $self->{changelog_io}->dbh($self->dbh) if $self->{changelog_io}->needs_dbh;
55 11 50       45 $self->{changelog_io}->schema($self->schema) if $self->schema;
56 11         88 return $self->{changelog_io};
57             }
58              
59             1; # End of Geoffrey::Role::Core
60              
61             __END__