blib/lib/Venus/Role/Proxyable.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 71.1% 37 / 52 SCAR 18.6
CC
6
Cov
77%
AUTOLOAD
5.9
BUILDPROXY
2.2
BEGIN
1.0
CRAP 6.4
« blib/lib/Venus/Core/Role.pm ↑ Summary blib/lib/Venus/Role/Defaultable.pm »
1 package Venus::Role::Proxyable;
2  
3 42 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 42 ▶use Venus::Role 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # METHODS
11  
12 sub AUTOLOAD {
13 105 ▶ require Venus::Error;
Subroutine AUTOLOAD: called CC=5 SCAR=17.8
14  
15 105 my ($package, $method) = our $AUTOLOAD =~ m[^(.+)::(.+)$];
16  
17 105 my $build = $package->can('BUILDPROXY');
18  
19 105 my $error = qq(Can't locate object method "$method" via package "$package");
20  
21 105 ▶ Venus::Error->throw($error) unless $build && ref($build) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $build and ref $build eq "CODE" 0 105 105
Condition33%1/3
$build and ref $build eq "CODE"
!ll&&!rl&&r
00105
MC/DC0%0/2
$build and ref $build eq "CODE"
$build ref $build eq "CODE"
Truth table33%1/3
A and B
A= $buildB= ref $build eq "CODE"
ABresult
0X0
100
111
22  
23 105 my $proxy = $build->($package, $method, @_);
24  
25 105 ▶ Venus::Error->throw($error) unless $proxy && ref($proxy) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $proxy and ref $proxy eq "CODE" 0 105 105
Condition33%1/3
$proxy and ref $proxy eq "CODE"
!ll&&!rl&&r
00105
MC/DC0%0/2
$proxy and ref $proxy eq "CODE"
$proxy ref $proxy eq "CODE"
Truth table33%1/3
A and B
A= $proxyB= ref $proxy eq "CODE"
ABresult
0X0
100
111
26  
27 105 goto &$proxy;
28 }
29  
30 sub BUILDPROXY {
31 105 ▶ require Venus::Error;
Subroutine BUILDPROXY: called CC=2 SCAR=7.9
Pod undocumented
32  
33 105 my ($package, $method, $self, @args) = @_;
34  
35 105 my $build = $self->can('build_proxy');
36  
37 105 ▶ return $build->($self, $package, $method, @args) if $build;
Branch: 1 branch
BranchTrueFalseTotal
if $build 105 0 105
38  
39 0 my $error = qq(Can't locate object method "build_proxy" via package "$package");
40  
41 0 Venus::Error->throw($error);
42 }
43  
44 # EXPORTS
45  
46 sub EXPORT {
47 46 ▶ ['AUTOLOAD', 'BUILDPROXY']
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
48 }
49  
50 42 1;
51  
52  
53  
54 =head1 NAME
55  
56 Venus::Role::Proxyable - Proxyable Role
57  
58 =cut
59  
60 =head1 ABSTRACT
61  
62 Proxyable Role for Perl 5
63  
64 =cut
65  
66 =head1 SYNOPSIS
67  
68 package Example;
69  
70 use Venus::Class;
71  
72 with 'Venus::Role::Proxyable';
73  
74 attr 'test';
75  
76 sub build_proxy {
77 my ($self, $package, $method, @args) = @_;
78 return sub { [$self, $package, $method, @args] } if $method eq 'anything';
79 return undef;
80 }
81  
82 package main;
83  
84 my $example = Example->new(test => time);
85  
86 # $example->anything(1..4);
87  
88 =cut
89  
90 =head1 DESCRIPTION
91  
92 This package provides a hook into method dispatch resoluton via a wrapper
93 around the C<AUTOLOAD> routine which processes calls to routines which don't
94 exist.
95  
96 =cut
97  
98 =head1 METHODS
99  
100 This package provides the following methods:
101  
102 =cut
103  
104 =head2 build_proxy
105  
106 build_proxy(string $package, string $method, any @args) (coderef | undef)
107  
108 The build_proxy method should return a code reference to fulfill the method
109 dispatching request, or undef to result in a method not found error.
110  
111 I<Since C<0.01>>
112  
113 =over 4
114  
115 =item build_proxy example 1
116  
117 package main;
118  
119 my $example = Example->new(test => 123);
120  
121 my $build_proxy = $example->build_proxy('Example', 'everything', 1..4);
122  
123 # undef
124  
125 =back
126  
127 =over 4
128  
129 =item build_proxy example 2
130  
131 package main;
132  
133 my $example = Example->new(test => 123);
134  
135 my $build_proxy = $example->build_proxy('Example', 'anything', 1..4);
136  
137 # sub { ... }
138  
139 =back
140  
141 =cut
142  
143 =head1 AUTHORS
144  
145 Awncorp, C<awncorp@cpan.org>
146  
147 =cut
148  
149 =head1 LICENSE
150  
151 Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>.
152  
153 This program is free software, you can redistribute it and/or modify it under
154 the terms of the Apache license version 2.0.
155  
156 =cut
« blib/lib/Venus/Core/Role.pm ↑ Summary blib/lib/Venus/Role/Defaultable.pm »