File Coverage

blib/lib/Inline/Select.pm
Criterion Covered Total %
statement 37 44 84.0
branch 10 22 45.4
condition n/a
subroutine 6 7 85.7
pod 0 3 0.0
total 53 76 69.7


line stmt bran cond sub pod time code
1             package Inline::Select ;
2              
3 2     2   536 use strict ;
  2         4  
  2         66  
4 2     2   9 use Carp ;
  2         4  
  2         130  
5 2     2   2403 use Data::Dumper ;
  2         17697  
  2         1094  
6              
7              
8             $Inline::Select::VERSION = '0.01' ;
9              
10             %Inline::Select::GROUPS = () ;
11              
12              
13             sub import {
14 0     0   0 my $class = shift ;
15            
16 0         0 return $class->bind(@_) ;
17             }
18              
19              
20             sub register {
21 1     1 0 2 my $class = shift ;
22 1         5 my %args = @_ ;
23              
24 1         3 my $group = delete $args{PACKAGE} ;
25 1 50       8 croak("PACKAGE configuration attribute not defined") unless $group ;
26              
27 1         2 my $inline = delete $args{Inline} ;
28 1 50       4 croak("Inline configuration attribute not defined") unless $inline ;
29 1 50       7 croak("Inline configuration attribute must be an ARRAY reference")
30             unless UNIVERSAL::isa($inline, 'ARRAY') ;
31              
32             # Registration mode
33 1         3 my $language = $inline->[0] ;
34 1         16 $Inline::Select::GROUPS{$group}->{$language} = $inline ;
35 1         3 debug($inline) ;
36             }
37              
38              
39             sub bind {
40 1     1 0 1335 my $class = shift ;
41 1         4 my %args = @_ ;
42              
43 1         4 my $group = delete $args{PACKAGE} ;
44 1 50       4 croak("PACKAGE configuration attribute not defined") unless $group ;
45              
46 1         2 my $inline = delete $args{Inline} ;
47 1 50       4 croak("Inline configuration attribute not defined") unless $inline ;
48 1 50       4 croak("Inline configuration attribute must be a SCALAR") unless ! ref($inline) ;
49              
50             # Selection mode
51 1         3 my $caller = caller() ;
52 1         6 debug(\%Inline::Select::GROUPS) ;
53 1         3 my $code = undef ;
54 1 50       6 if ($inline !~ /^perl$/i){
55 0         0 require Inline ;
56 0         0 $code = <
57             package $caller ;
58             use Inline (\@{\$Inline::Select::GROUPS{'$group'}->{'$inline'}}) ;
59             CODE
60             }
61             else {
62 1 50       10 croak("Source must be a CODE reference in the case of the 'Perl' language")
63             unless UNIVERSAL::isa($Inline::Select::GROUPS{$group}->{$inline}->[1], 'CODE') ;
64 1         5 $code = <
65             package $caller ;
66             \$Inline::Select::GROUPS{'$group'}->{'$inline'}->[1]->() ;
67             CODE
68             }
69 1         3 debug($code) ;
70 1         71 eval $code ;
71 1 50       853 croak($@) if $@ ;
72             }
73              
74              
75             sub debug {
76 3     3 0 4 my $msg = shift ;
77              
78 3 50       1658 if ($ENV{PERL_INLINE_SELECT_DEBUG}){
79 0 0         if (ref($msg)){
80 0           print STDERR Dumper($msg) ;
81             }
82             else{
83 0           print STDERR "$msg\n" ;
84             }
85             }
86             }
87              
88              
89              
90             1 ;