File Coverage

blib/lib/Data/TableData/Object.pm
Criterion Covered Total %
statement 28 31 90.3
branch 9 12 75.0
condition 1 3 33.3
subroutine 8 8 100.0
pod 2 2 100.0
total 48 56 85.7


line stmt bran cond sub pod time code
1             package Data::TableData::Object;
2              
3 4     4   220922 use 5.010001;
  4         44  
4 4     4   19 use strict;
  4         5  
  4         62  
5 4     4   14 use warnings;
  4         6  
  4         115  
6              
7 4     4   1684 use Data::Check::Structure qw(is_aos is_aoaos is_aohos);
  4         4949  
  4         209  
8 4     4   22 use Exporter qw(import);
  4         8  
  4         79  
9 4     4   17 use Scalar::Util qw(blessed);
  4         6  
  4         956  
10              
11             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12             our $DATE = '2022-05-19'; # DATE
13             our $DIST = 'Data-TableData-Object'; # DIST
14             our $VERSION = '0.116'; # VERSION
15              
16             our @EXPORT_OK = qw(table);
17              
18 54     54 1 25481 sub table { __PACKAGE__->new(@_) }
19              
20             sub new {
21 54     54 1 108 my ($class, $data, $spec) = @_;
22 54 50 33     315 if (!defined($data)) {
    50          
    100          
    100          
    100          
    50          
23 0         0 die "Please specify table data";
24             } elsif (blessed($data) && $data->isa("Data::TableData::Object::Base")) {
25 0         0 return $data;
26             } elsif (ref($data) eq 'HASH') {
27 18         378 require Data::TableData::Object::hash;
28 18         47 Data::TableData::Object::hash->new($data);
29             } elsif (is_aoaos($data)) {
30 10         1094 require Data::TableData::Object::aoaos;
31 10         31 Data::TableData::Object::aoaos->new($data, $spec);
32             } elsif (is_aohos($data)) {
33 9         1595 require Data::TableData::Object::aohos;
34 9         32 Data::TableData::Object::aohos->new($data, $spec);
35             } elsif (ref($data) eq 'ARRAY') {
36 17         1209 require Data::TableData::Object::aos;
37 17         53 Data::TableData::Object::aos->new($data);
38             } else {
39 0           die "Unknown table data form, please supply array of scalar, ".
40             "array of array-of-scalar, or array of hash-of-scalar";
41             }
42             }
43              
44             1;
45             # ABSTRACT: Manipulate table-like data structure via table object
46              
47             __END__