blib/lib/Venus/Role/Pluggable.pm

filter: Statementstmt 96.3% 26 / 27 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 86.3% 38 / 44 CC 4 SCAR 4.5
CC
4
Cov
91%
AUDIT
2.1
build_proxy
2.0
__ANON__
2.0
CRAP 1.6
« blib/lib/Venus/Role/Reflectable.pm ↑ Summary blib/lib/Venus/Kind/Value.pm »
1 package Venus::Role::Pluggable;
2  
3 59 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 # IMPORTS
11  
12 59 ▶use Venus::Role 'fault';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # AUDITS
15  
16 59 ▶sub AUDIT {
Subroutine AUDIT: called CC=2 SCAR=7.6
Pod undocumented
17 59 my ($self, $from) = @_;
18  
19 59 ▶ if (!$from->does('Venus::Role::Proxyable')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->does("Venus::Role::Proxyable")) 0 59 59
20 0 fault "${self} requires ${from} to consume Venus::Role::Proxyable";
21 }
22  
23 59 return $self;
24 }
25  
26 # BUILDERS
27  
28 2 ▶sub build_proxy {
Subroutine build_proxy: called CC=2 SCAR=6.9
Pod undocumented
29 2 my ($self, $package, $method, @args) = @_;
30  
31 2 require Venus::Space;
32  
33 2 my $space = Venus::Space->new($package)->child('plugin', $method);
34  
35 2 ▶ return undef if !$space->tryload;
Branch: 1 branch
BranchTrueFalseTotal
unless $space->tryload 0 2 2
36  
37 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
38 2 ▶ if ($space->package->can('construct')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($space->package->can('construct')) { } 1 1 2
39 1 my $class = $space->load;
40  
41 1 return $class->construct($self, @args)->execute;
42 }
43 else {
44 1 my $class = $space->load;
45  
46 1 return $class->new->execute($self, @args);
47 }
48 2 };
49 }
50  
51 # EXPORTS
52  
53 59 ▶sub EXPORT {
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
54 59 ['build_proxy']
55 }
56  
57 59 1;
58  
59  
60  
61 =head1 NAME
62  
63 Venus::Role::Pluggable - Pluggable Role
64  
65 =cut
66  
67 =head1 ABSTRACT
68  
69 Pluggable Role for Perl 5
70  
71 =cut
72  
73 =head1 SYNOPSIS
74  
75 package Example::Plugin::Username;
76  
77 use Venus::Class;
78  
79 use Digest::SHA ();
80  
81 sub execute {
82 my ($self, $example) = @_;
83  
84 return Digest::SHA::sha1_hex($example->login);
85 }
86  
87 package Example::Plugin::Password;
88  
89 use Venus::Class;
90  
91 use Digest::SHA ();
92  
93 attr 'value';
94  
95 sub construct {
96 my ($class, $example) = @_;
97  
98 return $class->new(value => $example->secret);
99 }
100  
101 sub execute {
102 my ($self) = @_;
103  
104 return Digest::SHA::sha1_hex($self->value);
105 }
106  
107 package Example;
108  
109 use Venus::Class;
110  
111 with 'Venus::Role::Proxyable';
112 with 'Venus::Role::Pluggable';
113  
114 attr 'login';
115 attr 'secret';
116  
117 package main;
118  
119 my $example = Example->new(login => 'admin', secret => 'p@ssw0rd');
120  
121 # $example->username;
122 # $example->password;
123  
124 =cut
125  
126 =head1 DESCRIPTION
127  
128 This package provides a mechanism for dispatching to plugin classes.
129  
130 =cut
131  
132 =head1 AUTHORS
133  
134 Awncorp, C<awncorp@cpan.org>
135  
136 =cut
137  
138 =head1 LICENSE
139  
140 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
141  
142 This program is free software, you can redistribute it and/or modify it under
143 the terms of the Apache license version 2.0.
144  
145 =cut
« blib/lib/Venus/Role/Reflectable.pm ↑ Summary blib/lib/Venus/Kind/Value.pm »