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 70     70   33580 use YAOO;
  70         148  
  70         403  
4              
5 70     70   53923 use ODS::Iterator;
  70         290  
  70         34629  
6              
7             auto_build;
8              
9             has table => isa(object);
10              
11             has serialize_class => isa(object);
12              
13             sub connect {
14 137     137 0 1012 my ($self, %params) = @_;
15 137         1469 $self = $self->new(%params);
16 137         34905 return $self;
17             }
18              
19             sub into_rows {
20 1765     1765 0 134403 my ($self, $data, $inflated) = @_;
21              
22 1765 100 66     5018 $data = $self->parse_data_format($data)
23             if (not ref $data and $self->can('parse_data_format'));
24              
25 1765 100       6441 if (ref $data eq 'ARRAY') {
    100          
26 43         154 my @rows;
27 43         180 for my $row ( @{ $data } ) {
  43         264  
28 919   100     9226 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 43         397 $self->table->rows(\@rows);
36              
37 43         51604 return ODS::Iterator->new(table => $self->table);
38             } elsif (ref $data eq 'HASH') {
39 1721   50     4525 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         7 return undef;
48             }
49              
50             sub into_storage {
51 1732     1732 0 2937 my ($self, $all) = @_;
52              
53 1732         2156 my $data;
54 1732 100 66     8757 if ($all && !ref $all) {
    50          
55 12         17 for my $row (@{ $self->table->rows }) {
  12         33  
56 44         259 my $val = $row->store_row();
57 44         67 push @{$data}, $val;
  44         126  
58             }
59             } elsif ($all) {
60 1720         4595 $data = $all->store_row();
61             } else {
62 0         0 $data = $self->table->rows->[-1]->store_row();
63             }
64              
65 1732 50 33     12406 $data = $self->stringify_data_format($data)
66             if (ref $data and $self->can('stringify_data_format'));
67              
68 1732         9660 return $data;
69             }
70              
71             1;
72