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