File Coverage

blib/lib/Data/Model/Driver.pm
Criterion Covered Total %
statement 43 58 74.1
branch 11 16 68.7
condition 2 3 66.6
subroutine 13 28 46.4
pod 0 20 0.0
total 69 125 55.2


line stmt bran cond sub pod time code
1             package Data::Model::Driver;
2 181     181   1412 use strict;
  181         360  
  181         5897  
3 181     181   1107 use warnings;
  181         591  
  181         4290  
4              
5 181     181   1023 use Carp ();
  181         314  
  181         136612  
6             $Carp::Internal{(__PACKAGE__)}++;
7              
8             sub new {
9 82     82 0 298455 my($class, %args) = @_;
10 82         534 my $self = bless { %args }, shift;
11 82         608 $self->init;
12 82         446 $self;
13             }
14              
15 28     28 0 75 sub init {}
16 168     168 0 540 sub attach_model {}
17 5     5 0 15 sub detach_model {}
18              
19 218     218 0 1650 sub cache_key_prefix { shift->{cache_key_prefix} }
20              
21             sub cache_key {
22 218     218 0 593 my($self, $schema, $id) = @_;
23              
24 218         452 Carp::confess 'The number of key is wrong'
25 218 50       330 unless scalar(@{ $id }) == scalar(@{ $schema->key });
  218         867  
26              
27 218 50       1355 join(':',
    50          
    50          
28             ($self->cache_key_prefix ? $self->cache_key_prefix : ()),
29             ($schema->options->{model_name_realname} ? $schema->options->{model_name_realname} : $schema->model),
30             (ref($id) eq 'ARRAY' ? @$id : $id)
31             );
32             }
33              
34              
35             my $KEYSEPARATE = "\0";
36             sub _generate_key_data {
37 1094     1094   1519 my($self, $key_array) = @_;
38 1094         1201 join $KEYSEPARATE, @{ $key_array };
  1094         3949  
39             }
40              
41             sub _generate_result_iterator {
42 216     216   366 my($self, $results) = @_;
43              
44 216         317 my $count = 0;
45 216         265 my $max = scalar @{ $results };
  216         358  
46             sub {
47 580     580   819 my $reset = shift;
48 580 50       1343 $count = 0 if $reset;
49 580 100       1575 return unless $count < $max;
50 366         1209 $results->[$count++];
51 216         1541 };
52             }
53              
54             sub _set_auto_increment {
55 519     519   2218 my($self, $schema, $columns, $code) = @_;
56 519         1389 my $count = 0;
57 519 100       1706 if (my @keys = @{ $schema->key }) {
  519         3891  
58 491         8795 for my $column (@keys) {
59 593 100 66     4297 if (exists $schema->column_options($column)->{auto_increment} &&
60             $schema->column_options($column)->{auto_increment}) {
61 176         772 $columns->{$column} = $code->();
62 176         902 $count++;
63             }
64             }
65             }
66 519         5764 $count;
67             }
68              
69 0     0     sub _as_sql_hook {}
70              
71 0     0 0   sub lookup {}
72 0     0 0   sub lookup_multi {}
73 0     0 0   sub get {}
74 0     0 0   sub set {}
75 0     0 0   sub delete {}
76 0     0 0   sub update {}
77 0     0 0   sub replace {}
78              
79 0     0 0   sub get_multi {}
80 0     0 0   sub set_multi {}
81 0     0 0   sub delete_multi {}
82              
83 0     0 0   sub txn_begin { Carp::croak 'not transaction support' }
84 0     0 0   sub txn_rollback { Carp::croak 'not transaction support' }
85 0     0 0   sub txn_commit { Carp::croak 'not transaction support' }
86 0     0 0   sub txn_end {}
87              
88             1;