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