File Coverage

blib/lib/KiokuDB/TypeMap/Shadow.pm
Criterion Covered Total %
statement 12 12 100.0
branch 2 2 100.0
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 17 18 94.4


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuDB::TypeMap::Shadow;
4 12     12   53 use Moose;
  12         22  
  12         85  
5              
6 12     12   60445 use namespace::clean -except => 'meta';
  12         22  
  12         112  
7              
8             with qw(KiokuDB::Role::TypeMap);
9              
10             has typemaps => (
11             does => "ArrayRef[KiokuDB::Role::TypeMap]",
12             is => "ro",
13             required => 1,
14             );
15              
16             sub resolve {
17 93     93 0 150 my ( $self, @args ) = @_;
18              
19 93         86 foreach my $typemap ( @{ $self->typemaps } ) {
  93         2317  
20 207 100       635 if ( my $entry = $typemap->resolve(@args) ) {
21 71         220 return $entry;
22             }
23             }
24              
25 22         87 return;
26             }
27              
28             __PACKAGE__->meta->make_immutable;
29              
30             __PACKAGE__
31              
32             __END__
33              
34             =pod
35              
36             =head1 NAME
37              
38             KiokuDB::TypeMap::Shadow - Try a list of L<KiokuDB::TypeMap>s in order
39              
40             =head1 SYNOPSIS
41              
42             KiokuDB->new(
43             backend => ...,
44             typemap => KiokuDB::TypeMap::Shadow->new(
45             typemaps => [
46             $first,
47             $second,
48             ],
49             ),
50             );
51              
52             =head1 DESCRIPTION
53              
54             This class is useful for performing mixin inheritence like merging of typemaps,
55             by shadowing an ordered list.
56              
57             This is used internally to overlay the user typemap on top of the
58             L<KiokuDB::TypeMap::Default> instance provided by the backend.
59              
60             This differs from using C<includes> in L<KiokuDB::TypeMap> because that
61             inclusion is computed symmetrically, like roles.
62              
63             =cut