blib/lib/Venus/Role/Accessible.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 50.0% 2 / 4 totaltotal 86.3% 38 / 44 CC 5 SCAR 6.4
CC
5
Cov
88%
assign
3.1
AUDIT
2.1
access
2.0
CRAP 1.9
« blib/lib/Venus/Regexp.pm ↑ Summary blib/lib/Venus/Role/Stashable.pm »
1 package Venus::Role::Accessible;
2  
3 119 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 119 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 119 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 119 ▶use Venus::Role 'fault';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # AUDITS
13  
14 375 ▶sub AUDIT {
Subroutine AUDIT: called CC=2 SCAR=7.6
Pod undocumented
15 375 my ($self, $from) = @_;
16  
17 375 ▶ if (!$from->isa('Venus::Core')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->isa("Venus::Core")) 0 375 375
18 0 fault "${self} requires ${from} to derive from Venus::Core";
19 }
20  
21 375 return $self;
22 }
23  
24 # METHODS
25  
26 10 ▶sub access {
Subroutine access: called CC=2 SCAR=6.9
Pod documented
27 10 my ($self, $name, @args) = @_;
28  
29 10 ▶ return if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 9 10
30  
31 9 return $self->$name(@args);
32 }
33  
34 4 ▶sub assign {
Subroutine assign: called CC=3 SCAR=11.4
Pod documented
35 4 my ($self, $name, $code, @args) = @_;
36  
37 4 ▶ return if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 4 4
38 4 ▶ return if !$code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 4 4
39  
40 4 return $self->access($name, $self->$code(@args));
41 }
42  
43 # EXPORTS
44  
45 375 ▶sub EXPORT {
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
46 375 ['access', 'assign']
47 }
48  
49 119 1;
50  
51  
52  
53 =head1 NAME
54  
55 Venus::Role::Accessible - Accessible Role
56  
57 =cut
58  
59 =head1 ABSTRACT
60  
61 Accessible Role for Perl 5
62  
63 =cut
64  
65 =head1 SYNOPSIS
66  
67 package Example;
68  
69 use Venus::Class;
70  
71 with 'Venus::Role::Accessible';
72  
73 attr 'value';
74  
75 sub downcase {
76 lc $_[0]->value
77 }
78  
79 sub upcase {
80 uc $_[0]->value
81 }
82  
83 package main;
84  
85 my $example = Example->new(value => 'hello, there');
86  
87 # $example->value;
88  
89 =cut
90  
91 =head1 DESCRIPTION
92  
93 This package modifies the consuming package and provides the C<access> method
94 for getting and setting attributes.
95  
96 =cut
97  
98 =head1 METHODS
99  
100 This package provides the following methods:
101  
102 =cut
103  
104 =head2 access
105  
106 access(string $name, any $value) (any)
107  
108 The access method gets or sets the class attribute specified.
109  
110 I<Since C<1.23>>
111  
112 =over 4
113  
114 =item access example 1
115  
116 # given: synopsis
117  
118 package main;
119  
120 my $access = $example->access;
121  
122 # undef
123  
124 =back
125  
126 =over 4
127  
128 =item access example 2
129  
130 # given: synopsis
131  
132 package main;
133  
134 my $access = $example->access('value');
135  
136 # "hello, there"
137  
138 =back
139  
140 =over 4
141  
142 =item access example 3
143  
144 # given: synopsis
145  
146 package main;
147  
148 my $access = $example->access('value', 'something');
149  
150 # "something"
151  
152 =back
153  
154 =over 4
155  
156 =item access example 4
157  
158 # given: synopsis
159  
160 package main;
161  
162 my $instance = $example;
163  
164 # bless({}, "Example")
165  
166 $example->access('value', 'something');
167  
168 # "something"
169  
170 $instance = $example;
171  
172 # bless({value => "something"}, "Example")
173  
174 =back
175  
176 =cut
177  
178 =head2 assign
179  
180 assign(string $name, string | coderef $code, any @args) (any)
181  
182 The assign method dispatches the method call or executes the callback, sets the
183 class attribute specified to the result, and returns the result.
184  
185 I<Since C<1.23>>
186  
187 =over 4
188  
189 =item assign example 1
190  
191 # given: synopsis
192  
193 package main;
194  
195 my $assign = $example->assign('value', 'downcase');
196  
197 # "hello, there"
198  
199 =back
200  
201 =over 4
202  
203 =item assign example 2
204  
205 # given: synopsis
206  
207 package main;
208  
209 my $assign = $example->assign('value', 'upcase');
210  
211 # "HELLO, THERE"
212  
213 =back
214  
215 =over 4
216  
217 =item assign example 3
218  
219 # given: synopsis
220  
221 package main;
222  
223 my $instance = $example;
224  
225 # bless({value => "hello, there"}, "Example")
226  
227 my $assign = $example->assign('value', 'downcase');
228  
229 # "hello, there"
230  
231 $instance = $example;
232  
233 # bless({value => "hello, there"}, "Example")
234  
235 =back
236  
237 =cut
238  
239 =head1 AUTHORS
240  
241 Awncorp, C<awncorp@cpan.org>
242  
243 =cut
244  
245 =head1 LICENSE
246  
247 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
248  
249 This program is free software, you can redistribute it and/or modify it under
250 the terms of the Apache license version 2.0.
251  
252 =cut
« blib/lib/Venus/Regexp.pm ↑ Summary blib/lib/Venus/Role/Stashable.pm »