File Coverage

lib/File/DataClass/Result.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 4 4 100.0
total 26 26 100.0


line stmt bran cond sub pod time code
1             package File::DataClass::Result;
2              
3 4     4   651 use namespace::autoclean;
  4         4  
  4         22  
4              
5 4     4   236 use Moo;
  4         6  
  4         20  
6 4     4   1167 use File::DataClass::Types qw( Object Str );
  4         7  
  4         28  
7              
8             has 'id' => is => 'rw', isa => Str, required => 1;
9              
10             has '_result_source' => is => 'ro', isa => Object,
11             handles => { _path => 'path', _storage => 'storage' },
12             init_arg => 'result_source', reader => 'result_source',
13             required => 1, weak_ref => 1;
14              
15             around 'BUILDARGS' => sub {
16             my ($orig, $self, @args) = @_; my $attr = $orig->( $self, @args );
17              
18             my $name = delete $attr->{name}; $attr->{id} //= $name;
19              
20             return $attr;
21             };
22              
23             sub delete {
24 6     6 1 751 return $_[ 0 ]->_storage->delete( $_[ 0 ]->_path, $_[ 0 ] );
25             }
26              
27             sub insert {
28 6     6 1 418 return $_[ 0 ]->_storage->insert( $_[ 0 ]->_path, $_[ 0 ] );
29             }
30              
31             sub name { # Deprecated
32 2 100   2 1 1771 return defined $_[ 1 ] ? $_[ 0 ]->id( $_[ 1 ] ) : $_[ 0 ]->id;
33             }
34              
35             sub update {
36 11     11 1 185 return $_[ 0 ]->_storage->update( $_[ 0 ]->_path, $_[ 0 ] );
37             }
38              
39             1;
40              
41             __END__