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