File Coverage

lib/File/DataClass/ResultSource.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 12 12 100.0
pod 3 3 100.0
total 50 50 100.0


line stmt bran cond sub pod time code
1             package File::DataClass::ResultSource;
2              
3 3     3   19 use namespace::autoclean;
  3         8  
  3         22  
4              
5 3     3   231 use File::DataClass::Constants qw( FALSE NUL TRUE );
  3         8  
  3         122  
6 3     3   1091 use File::DataClass::ResultSet;
  3         10  
  3         107  
7 3         28 use File::DataClass::Types qw( ArrayRef ClassName HashRef
8 3     3   25 Object SimpleStr Str );
  3         7  
9 3     3   3872 use Moo;
  3         9  
  3         15  
10              
11             # Private functions
12             my $_build_attributes = sub {
13 1     1   13 my $self = shift; my $attr = {};
  1         2  
14              
15 1         3 $attr->{ $_ } = TRUE for (@{ $self->attributes });
  1         7  
16              
17 1         15 return $attr;
18             };
19              
20             # Public attributes
21             has 'attributes' => is => 'ro', isa => ArrayRef[Str],
22             required => TRUE;
23              
24 4     4   8474 has 'defaults' => is => 'ro', isa => HashRef, builder => sub { {} };
25              
26             has 'name' => is => 'ro', isa => SimpleStr, required => TRUE;
27              
28             has 'label_attr' => is => 'ro', isa => SimpleStr, default => NUL;
29              
30 6     6   4557 has 'resultset_attributes' => is => 'ro', isa => HashRef, builder => sub { {} };
31              
32             has 'resultset_class' => is => 'ro', isa => ClassName,
33             default => 'File::DataClass::ResultSet';
34              
35             has 'schema' => is => 'ro', isa => Object,
36             handles => [ 'path', 'storage' ],
37             required => TRUE, weak_ref => TRUE;
38              
39 5     5   510 has 'types' => is => 'ro', isa => HashRef, builder => sub { {} };
40              
41             has '_attributes' => is => 'lazy', isa => HashRef,
42             builder => $_build_attributes, init_arg => undef;
43              
44             # Public methods
45             sub columns {
46 1     1 1 12 return @{ $_[ 0 ]->attributes };
  1         8  
47             }
48              
49             sub has_column {
50 3   100 3 1 15 my $key = $_[ 1 ] // '_invalid_key_';
51              
52 3 100       63 return exists $_[ 0 ]->_attributes->{ $key } ? TRUE : FALSE;
53             }
54              
55             sub resultset {
56 20     20 1 44 my $self = shift;
57              
58 20         39 my $attrs = { %{ $self->resultset_attributes }, result_source => $self };
  20         80  
59              
60 20         333 return $self->resultset_class->new( $attrs );
61             }
62              
63             1;
64              
65             __END__