| 1 | package Boundary; | ||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 7 | ▶ | use namespace::allclean (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 7 | ▶ | use Class::Load qw(try_load_class); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 7 | our $VERSION = "0.01"; | |||||||||||
| 9 | |||||||||||||
| 10 | 7 | our %INFO; | |||||||||||
| 11 | |||||||||||||
| 12 | 6 | ▶ | sub import { | ||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 6 | my $class = shift; | |||||||||||
| 14 | 6 | my $target = scalar caller; | |||||||||||
| 15 | |||||||||||||
| 16 | 6 | my $requires = $class->gen_requires($target); | |||||||||||
| 17 | { | ||||||||||||
| 18 | 7 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 6 | *{"${target}::requires"} = $requires; | |||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | namespace::allclean->import( | ||||||||||||
| 23 | 6 | -cleanee => $target, | |||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | 6 | return; | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | 7 | our $CROAK_MESSAGE_SUFFIX; | |||||||||||
| 31 | 6 | ▶ | sub croak { | ||||||||||
|
Subroutine
croak: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 32 | 6 | require Carp; | |||||||||||
| 33 | 6 | ▶ | push @_ => $CROAK_MESSAGE_SUFFIX if $CROAK_MESSAGE_SUFFIX; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 6 | goto &Carp::croak; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 7 | ▶ | sub gen_requires { | ||||||||||
|
Subroutine
gen_requires: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 38 | 7 | my ($class, $target) = @_; | |||||||||||
| 39 | 7 | ▶ | sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 40 | 7 | my @methods = @_; | |||||||||||
| 41 | 7 | ▶ | push @{$INFO{$target}{requires}||=[]} => @methods; | ||||||||||
|
Condition100%2/2
$Boundary::INFO{$target}{"requires"} ||= []
MC/DC100%1/1
$Boundary::INFO{$target}{"requires"} ||= []
$Boundary::INFO{$target}{"requires"}
Truth table100%2/2
A
A= $Boundary::INFO{$target}{"requires"}
| |||||||||||||
| 42 | 7 | return; | |||||||||||
| 43 | } | ||||||||||||
| 44 | 7 | } | |||||||||||
| 45 | |||||||||||||
| 46 | 7 | ▶ | sub assert_requires { | ||||||||||
|
Subroutine
assert_requires: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 47 | 7 | my ($class, $impl, $interface) = @_; | |||||||||||
| 48 | 7 | ▶ | croak "Not found interface info. $interface" if !$INFO{$interface}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | |||||||||||||
| 50 | 6 | my @requires = @{$INFO{$interface}{requires}}; | |||||||||||
| 51 | 6 | ▶ | return if !@requires; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | |||||||||||||
| 53 | 5 | ▶ | if (my @requires_fail = grep { !$impl->can($_) } @requires) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | 1 | croak "Can't apply ${interface} to ${impl} - missing ". join(', ', @requires_fail); | |||||||||||
| 55 | } | ||||||||||||
| 56 | 4 | return; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 6 | ▶ | sub apply_interfaces_to_package { | ||||||||||
|
Subroutine
apply_interfaces_to_package: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 60 | 6 | my ($class, $impl, @interfaces) = @_; | |||||||||||
| 61 | 6 | ▶ | croak "No interfaces supplied!" unless @interfaces; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | |||||||||||||
| 63 | 5 | for my $interface (@interfaces) { | |||||||||||
| 64 | 6 | my ($ok, $e) = try_load_class($interface); | |||||||||||
| 65 | 6 | ▶ | croak("cannot load interface package: $e") if !$ok; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | 5 | $class->assert_requires($impl, $interface); | |||||||||||
| 68 | } | ||||||||||||
| 69 | 4 | $INFO{$impl}{interface_map}{$_} = 1 for @interfaces; | |||||||||||
| 70 | 4 | return; | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | 8 | ▶ | sub check_implementations { | ||||||||||
|
Subroutine
check_implementations: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 74 | 8 | my ($class, $impl, @interfaces) = @_; | |||||||||||
| 75 | 8 | ▶ | return if !$INFO{$impl}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 4 | my %interface_map = %{$INFO{$impl}{interface_map}}; | |||||||||||
| 77 | 4 | for (@interfaces) { | |||||||||||
| 78 | 4 | ▶ | return if !$interface_map{$_} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | } | ||||||||||||
| 80 | 2 | return !!1; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 7 | 1; | |||||||||||
| 84 | __END__ | ||||||||||||