File Coverage

blib/lib/Story/Interact/PageSource/DBI.pm
Criterion Covered Total %
statement 29 32 90.6
branch 2 2 100.0
condition n/a
subroutine 10 11 90.9
pod 0 2 0.0
total 41 47 87.2


line stmt bran cond sub pod time code
1 5     5   118 use 5.010001;
  5         24  
2 5     5   44 use strict;
  5         14  
  5         125  
3 5     5   43 use warnings;
  5         10  
  5         333  
4              
5             package Story::Interact::PageSource::DBI;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.001012';
9              
10 5     5   32 use Moo;
  5         13  
  5         43  
11 5     5   2111 use Types::Common -types;
  5         59  
  5         54  
12 5     5   73118 use Types::Path::Tiny -types;
  5         235704  
  5         46  
13 5     5   7381 use namespace::clean;
  5         22  
  5         67  
14              
15             with 'Story::Interact::PageSource';
16              
17             has 'dbh' => (
18             is => 'ro',
19             isa => Object,
20             required => 1,
21             );
22              
23             has 'sth' => (
24             is => 'lazy',
25             isa => Object,
26 2     2   32 builder => sub { my $s = shift; $s->dbh->prepare( $s->sql ) },
  2         40  
27             );
28              
29             has 'sql' => (
30             is => 'lazy',
31             isa => Str,
32 2     2   48 builder => sub { 'SELECT content FROM page WHERE id=?' }
33             );
34              
35             sub _build_sth {
36            
37             return ;
38             }
39              
40             sub get_source_code {
41 14     14 0 25 my ( $self, $page_id ) = @_;
42 14         251 my $sth = $self->sth;
43 14         1803 $sth->execute( $page_id );
44 14 100       263 if ( my ( $content ) = $sth->fetchrow_array ) {
45 12         64 return $content;
46             }
47 2         60 return;
48             }
49              
50             sub all_page_ids {
51 0     0 0   my ( $self ) = @_;
52 0           map $_->[0], @{ $self->dbh->selectall_arrayref('SELECT id FROM page') };
  0            
53             }
54              
55             1;