File Coverage

blib/lib/Data/Validate/CSV/Schema.pm
Criterion Covered Total %
statement 20 36 55.5
branch 0 2 0.0
condition 0 4 0.0
subroutine 7 13 53.8
pod 0 4 0.0
total 27 59 45.7


line stmt bran cond sub pod time code
1 1     1   16 use v5.12;
  1         4  
2 1     1   6 use strict;
  1         3  
  1         24  
3 1     1   6 use warnings;
  1         3  
  1         63  
4              
5             package Data::Validate::CSV::Schema;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.002';
9              
10 1     1   7 use Moo;
  1         3  
  1         7  
11 1     1   364 use Data::Validate::CSV::Types -types;
  1         3  
  1         10  
12 1     1   6240 use PerlX::Maybe;
  1         2402  
  1         4  
13 1     1   43 use namespace::autoclean;
  1         2  
  1         9  
14              
15             has columns => (
16             is => 'lazy',
17             isa => ArrayRef[Column],
18 0     0     builder => sub { [] },
19             coerce => 1,
20             );
21              
22             has notes => (
23             is => 'lazy',
24             isa => ArrayRef[Note],
25 0     0     builder => sub { [] },
26             coerce => 1,
27             );
28              
29             has primary_key => (
30             is => 'ro',
31             isa => ArrayRef->of(Str)->plus_coercions(Str, '[$_]'),
32             coerce => 1,
33             );
34              
35             sub new_from_file {
36 0     0 0   my $class = shift;
37 0           require Path::Tiny;
38 0           my $file = Path::Tiny::path(@_);
39 0           $class->new_from_json( $file->slurp_utf8 );
40             }
41              
42             sub new_from_json {
43 0     0 0   my $class = shift;
44 0           my ($str) = @_;
45 0           require JSON::PP;
46 0 0         $class->new_from_hashref( JSON::PP->new->decode(ref $str ? $$str : $str) );
47             }
48              
49             sub new_from_hashref {
50 0     0 0   my $class = shift;
51 0           my ($schema) = @_;
52             $class->new(
53             notes => $schema->{notes} || [],
54             columns => $schema->{tableSchema}{columns} || [],
55             maybe primary_key => $schema->{tableSchema}{primaryKey},
56 0   0       );
      0        
57             }
58              
59             sub clone_columns {
60 0     0 0   my $self = shift;
61 0           require Storable;
62 0           Storable::dclone($self->columns);
63             }
64              
65             1;