File Coverage

blib/lib/ODS/Storage/Base.pm
Criterion Covered Total %
statement 31 32 96.8
branch 10 12 83.3
condition 8 13 61.5
subroutine 5 5 100.0
pod 0 3 0.0
total 54 65 83.0


line stmt bran cond sub pod time code
1             package ODS::Storage::Base;
2              
3 72     72   38310 use YAOO;
  72         210  
  72         442  
4              
5 72     72   52513 use ODS::Iterator;
  72         267  
  72         27173  
6              
7             auto_build;
8              
9             has table => isa(object);
10              
11             has serialize_class => isa(object);
12              
13             sub connect {
14 142     142 0 1093 my ($self, %params) = @_;
15 142         1495 $self = $self->new(%params);
16 142         31109 return $self;
17             }
18              
19             sub into_rows {
20 1768     1768 0 73270 my ($self, $data, $inflated) = @_;
21              
22 1768 100 66     8146 $data = $self->parse_data_format($data)
23             if (not ref $data and $self->can('parse_data_format'));
24              
25 1768 100       10591 if (ref $data eq 'ARRAY') {
    100          
26 46         123 my @rows;
27 46         179 for my $row ( @{ $data } ) {
  46         352  
28 922   100     5326 push @rows, $self->table->row_class->new(
29             table => $self->table,
30             data => $row,
31             inflated => $inflated || 0,
32             serialize_class => $self->serialize_class
33             );
34             }
35 46         330 $self->table->rows(\@rows);
36              
37 46         50674 return ODS::Iterator->new(table => $self->table);
38             } elsif (ref $data eq 'HASH') {
39 1721   50     8170 return $self->table->row_class->new(
40             table => $self->table,
41             data => $data,
42             inflated => $inflated || 0,
43             serialize_class => $self->serialize_class
44             );
45             }
46              
47 1         16 return undef;
48             }
49              
50             sub into_storage {
51 1732     1732 0 6412 my ($self, $all) = @_;
52              
53 1732         3528 my $data;
54 1732 100 66     19337 if ($all && !ref $all) {
    50          
55 12         15 for my $row (@{ $self->table->rows }) {
  12         25  
56 44         179 my $val = $row->store_row();
57 44         61 push @{$data}, $val;
  44         97  
58             }
59             } elsif ($all) {
60 1720         9304 $data = $all->store_row();
61             } else {
62 0         0 $data = $self->table->rows->[-1]->store_row();
63             }
64              
65 1732 50 33     23823 $data = $self->stringify_data_format($data)
66             if (ref $data and $self->can('stringify_data_format'));
67              
68 1732         13708 return $data;
69             }
70              
71             1;
72