| 1 | package Templ; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Scope::Upper qw(localize UP); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use File::Find; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use File::Spec::Functions qw(catdir abs2rel curdir splitdir); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | our $VERSION = "0.01_01"; | |||||||||||||||||||
| 12 | 1 | $VERSION = eval $VERSION; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | our $spec_class; | |||||||||||||||||||
| 15 | BEGIN { | ||||||||||||||||||||
| 16 | 1 | ▶ | $Templ::spec_class = 'Templ::Spec::Basic'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 17 | # Somewhat inspired by Module::Find... | ||||||||||||||||||||
| 18 | # Perform a "require MODULE;" for all Templ::* modules | ||||||||||||||||||||
| 19 | 1 | foreach my $dir ( grep { -d } map { catdir($_,'Templ') } @INC ) { | |||||||||||||||||||
| 20 | my $wanted = sub { | ||||||||||||||||||||
| 21 | 51 | ▶ | return unless -r; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
Branch: 1 branch
| |||||||||||||||||||||
| 22 | 51 | ▶ | return if abs2rel($_,$dir) !~ m/^(.*)\.pm$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 39 | my $module = join( '::', 'Templ', splitdir($1) ); | |||||||||||||||||||
| 24 | 39 | ▶ | return unless $module =~ m/^(\w+::)*\w+$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 39 | ▶ | return if $Templ::loaded{$module}++; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 13 | eval "require $module;"; | |||||||||||||||||||
| 27 | 13 | ▶ | $@ && croak $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 3 | }; | |||||||||||||||||||
| 29 | # Find the perl modules under thes dirs and "require" them | ||||||||||||||||||||
| 30 | 3 | find( { wanted => $wanted, no_chdir => 1, follow => 1 }, $dir ); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | ▶ | sub templ ($;$) { $spec_class->templ( @_ ) } | ||||||||||||||||||
|
Subroutine
templ: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 35 | 1 | ▶ | sub templ_method ($$;$) { $spec_class->templ_method( @_ ) } | ||||||||||||||||||
|
Subroutine
templ_method: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 36 | 0 | ▶ | sub templ_sub ($$;$) { $spec_class->templ_sub( @_ ) } | ||||||||||||||||||
|
Subroutine
templ_sub: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | sub templ_spec (;$$) { | ||||||||||||||||||||
| 39 | 5 | ▶ | return $spec_class unless scalar @_; | ||||||||||||||||||
|
Subroutine
templ_spec: called CC=5 SCAR=16.3
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 2 | my $new_spec_class = shift; | |||||||||||||||||||
| 41 | 2 | ▶ | my $context = shift || UP; | ||||||||||||||||||
|
Condition66%2/3
shift() || &UP()
MC/DC50%1/2
shift() || &UP()
shift()
&UP()
Truth table66%2/3
A || B
A= shift()B= &UP()
| |||||||||||||||||||||
| 42 | 2 | ▶ | if ( not Templ::Spec::_subclass_loaded($new_spec_class) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 2 | ▶ | if ( $Templ::loaded{'Templ::Spec::'.$new_spec_class} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 2 | $new_spec_class = 'Templ::Spec::'.$new_spec_class; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 2 | Templ::Spec::_load_subclass($new_spec_class); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 2 | localize '$Templ::spec_class', $new_spec_class, $context; | |||||||||||||||||||
| 49 | 2 | return $new_spec_class; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub import { | ||||||||||||||||||||
| 53 | 2 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.7
| |||||||||||||||||||||
| 54 | 2 | my %valid_exports = map { $_ => 1 } qw(templ templ_method templ_sub templ_spec); | |||||||||||||||||||
| 55 | 2 | my @export = (); | |||||||||||||||||||
| 56 | 2 | ▶ | while (scalar @_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 1 | my $item = shift @_; | |||||||||||||||||||
| 58 | 1 | ▶ | if ($item eq '-spec') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 1 | templ_spec( shift(@_), UP ); | |||||||||||||||||||
| 60 | 1 | next; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 0 | ▶ | if (not exists $valid_exports{$item}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | croak "Unknown function: $item"; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 0 | push @export, $item; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 2 | ▶ | unless (scalar @export) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 2 | @export = keys %valid_exports; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 2 | foreach ( qw(templ templ_method templ_sub templ_spec) ) { | |||||||||||||||||||
| 71 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 72 | 8 | *{caller().'::'.$_} = \*{$_}; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||