File Coverage

blib/lib/DBIx/Class/Relationship/Abbreviate.pm
Criterion Covered Total %
statement 23 24 95.8
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 32 34 94.1


line stmt bran cond sub pod time code
1 1     1   1878 use strict;
  1         3  
  1         35  
2 1     1   5 use warnings;
  1         3  
  1         55  
3              
4             package DBIx::Class::Relationship::Abbreviate;
5              
6 1     1   12 use Carp qw/ croak /;
  1         3  
  1         377  
7              
8             sub import {
9 3     3   7876 my (undef, @fns) = @_;
10              
11 3         27 my ($ns) = caller =~ m/([\w:]+::Result)::\w+$/;
12              
13 3 100       16 croak qq{Cannot find result namespace in '@{[ scalar caller ]}'} unless $ns;
  1         217  
14              
15             my %export = (
16 2     2   15 result => sub { my ($class) = @_; $ns.'::'.$class },
  2         16  
17 2         15 );
18              
19 2         6 for my $fn (@fns) {
20 2 50       9 if ($export{$fn}) {
21 1     1   12 no strict 'refs';
  1         3  
  1         153  
22 2         5 *{caller.'::'.$fn} = $export{$fn};
  2         26  
23             } else {
24 0           croak qq{Illegal function name '$fn'};
25             }
26             }
27             }
28              
29             1;
30              
31             # ABSTRACT: allows you to abbreviate result class names in your relationships