File Coverage

blib/lib/Data/Model/Mixin.pm
Criterion Covered Total %
statement 29 30 96.6
branch 4 6 66.6
condition 1 3 33.3
subroutine 6 6 100.0
pod n/a
total 40 45 88.8


line stmt bran cond sub pod time code
1             package Data::Model::Mixin;
2 3     3   135918 use strict;
  3         7  
  3         100  
3 3     3   16 use warnings;
  3         5  
  3         75  
4              
5 3     3   16 use Carp ();
  3         6  
  3         532  
6             $Carp::Internal{(__PACKAGE__)}++;
7              
8             sub import {
9 3     3   32 my($class, %args) = @_;
10 3 50 33     44 Carp::croak "Usage: use Data::Model::Mixin modules => ['MixinModuleName', 'MixinModuleName2', .... ]"
11             unless $args{modules} && ref($args{modules}) eq 'ARRAY';
12              
13 3         8 my $caller = caller;
14 3         6 for my $module (@{ $args{modules} }) {
  3         10  
15 3         6 my $pkg = $module;
16 3 100       21 $pkg = __PACKAGE__ . "::$pkg" unless $pkg =~ s/^\+//;
17              
18 3     3   1945 eval "use $pkg"; ## no critic
  3         193  
  3         49  
  3         168  
19 3 50       12 if ($@) {
20 0         0 Carp::croak $@;
21             }
22              
23 3         11 my $register_methods = $pkg->register_method;
24 3         16 while (my($method, $code) = each %{ $register_methods }) {
  7         2279  
25 3     3   18 no strict 'refs';
  3         7  
  3         393  
26 4         5 *{"$caller\::$method"} = $code;
  4         22  
27             }
28             }
29             }
30              
31              
32             1;
33              
34             =head1 NAME
35              
36             Data::Model::Mixin - mixin manager for Data::Model
37              
38             =head1 SYNOPSIS
39              
40             use Data::Model::Mixin modules => ['mixin_module_names'];
41              
42             =head1 AUTHOR
43              
44             Kazuhiro Osawa Eyappo shibuya plE
45              
46             =head1 LICENSE
47              
48             This library is free software; you can redistribute it and/or modify
49             it under the same terms as Perl itself.
50              
51             =cut