File Coverage

blib/lib/MongoDBx/Tiny/Relation.pm
Criterion Covered Total %
statement 12 19 63.1
branch 0 2 0.0
condition n/a
subroutine 4 6 66.6
pod 1 1 100.0
total 17 28 60.7


line stmt bran cond sub pod time code
1             package MongoDBx::Tiny::Relation;
2 1     1   1227 use strict;
  1         2  
  1         30  
3 1     1   5 use warnings;
  1         2  
  1         32  
4              
5             =head1 NAME
6              
7             MongoDBx::Tiny::Relation - define relation
8              
9             =cut
10              
11 1     1   5 use Carp qw(carp confess);
  1         2  
  1         84  
12             our @ISA = qw/Exporter/;
13             our @EXPORT = qw/RELATION_DEFAULT/;
14              
15             {
16 1     1   6 no warnings qw(once);
  1         2  
  1         165  
17             *RELATION_DEFAULT = \&RELATION_BY;
18             }
19              
20             =head1 EXPORT
21              
22             =head2 RELATION_BY
23              
24             RELATION 'related_collection', RELATION_BY('method','related_field','field');
25             RELATION 'bar', RELATION_BY('single','foo_id','id');
26              
27             =cut
28              
29             sub RELATION_BY {
30 0     0 1   my ($meth,$field_name,$val_name) = @_;
31 0 0         confess "RELATION_BY: invalid args" if scalar @_ != 3;
32              
33             return sub {
34 0     0     my $self = shift;
35 0           my $c_name = shift; # relation
36 0           my $tiny = $self->tiny;
37 0           $tiny->$meth($c_name,{ $field_name => $self->$val_name() });
38             }
39 0           }
40              
41              
42             1;
43             __END__