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   6 use strict;
  1         2  
  1         34  
3 1     1   5 use warnings;
  1         2  
  1         33  
4              
5             =head1 NAME
6              
7             MongoDBx::Tiny::Relation - define relation
8              
9             =cut
10              
11 1     1   6 use Carp qw(carp confess);
  1         2  
  1         89  
12             our @ISA = qw/Exporter/;
13             our @EXPORT = qw/RELATION_DEFAULT/;
14              
15             {
16 1     1   6 no warnings qw(once);
  1         13  
  1         162  
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__
44              
45             =head1 AUTHOR
46              
47             Naoto ISHIKAWA, C<< <toona at seesaa.co.jp> >>
48              
49             =head1 LICENSE AND COPYRIGHT
50              
51             Copyright 2013 Naoto ISHIKAWA.
52              
53             This program is free software; you can redistribute it and/or modify it
54             under the terms of either: the GNU General Public License as published
55             by the Free Software Foundation; or the Artistic License.
56              
57             See http://dev.perl.org/licenses/ for more information.
58              
59              
60             =cut