lib/Object/Disoriented.pm

filter: Statementstmt 93.5% 29 / 31 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 86.6% 39 / 45 CC 5 SCAR 11.0
CC
5
Cov
86%
import
5.4
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 package Object::Disoriented;
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 our $VERSION = '0.02';
7  
8 1 ▶use Carp qw<croak>;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶sub import {
Subroutine import: called CC=5 SCAR=16.8
11 2 my (undef, $package, @functions) = @_;
12  
13 2 ▶ croak "What functions in $package do you want to disorient?"
Branch: 1 branch
BranchTrueFalseTotal
unless @functions 0 2 2
14 if !@functions;
15  
16 2 ▶ if (!eval "CORE::require $package; 1") {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "CORE::require $package; 1") 0 2 2
17 # Make the error message look like the caller's.
18 0 $@ =~ s/\n* \s+ at \s+ \(eval \s+ \d+\) \s+ line \s+ \d+\.\n*\z//xms;
19 0 croak $@;
20 }
21  
22 # Create a (presumably spurious) instance
23 2 my $instance = $package->new;
24  
25 # Ensure all desired functions exist as methods
26 2 my @missing = grep { !$instance->can($_) } @functions;
27 2 ▶ croak "Methods not found in $package: @missing"
Branch: 1 branch
BranchTrueFalseTotal
if @missing 0 2 2
28 if @missing;
29  
30 # Build a sub for each desired function
31 2 my $caller = caller;
32 2 for my $name (@functions) {
33 4 ▶ set_symbol($caller, $name, sub { $instance->$name(@_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
34 }
35  
36 2 return;
37 }
38  
39 4 ▶sub set_symbol {
Subroutine set_symbol: called CC=1 SCAR=0.0
Pod undocumented
40 4 my ($package, $name, $value) = @_;
41 1 ▶ no strict qw<refs>;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 4 *{"$package\::$name"} = $value;
43 }
44  
45 1 1;
46 __END__
↑ Summary