blib/lib/Venus/Role/Reflectable.pm

filter: Statementstmt 100% 28 / 28 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 83.3% 5 / 6 totaltotal 88.6% 47 / 53 SCAR 13.9
CC
4
Cov
91%
type
3.0
class
2.3
BEGIN
1.0
CRAP 4.0
« blib/lib/Venus/Role/Pluggable.pm ↑ Summary blib/lib/Venus/Role/Explainable.pm »
1 package Venus::Role::Reflectable;
2  
3 96 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 96 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 96 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 96 ▶use Venus::Role 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # METHODS
11  
12 sub class {
13 792 ▶ my ($self) = @_;
Subroutine class: called CC=2 SCAR=8.1
Pod documented
14  
15 792 ▶ return ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
79200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
16 }
17  
18 sub meta {
19 8 ▶ my ($self) = @_;
Subroutine meta: called CC=1 SCAR=0.0
Pod documented
20  
21 8 require Venus::Meta;
22  
23 8 return Venus::Meta->new(name => $self->class);
24 }
25  
26 sub reify {
27 3 ▶ my ($self, $method, @args) = @_;
Subroutine reify: called CC=1 SCAR=0.0
Pod documented
28  
29 3 return $self->type($method, @args)->deduce;
30 }
31  
32 sub space {
33 1 ▶ my ($self) = @_;
Subroutine space: called CC=1 SCAR=0.0
Pod documented
34  
35 1 require Venus::Space;
36  
37 1 return Venus::Space->new($self->class);
38 }
39  
40 sub type {
41 5 ▶ my ($self, $method, @args) = @_;
Subroutine type: called CC=3 SCAR=11.0
Pod documented
42  
43 5 require Venus::Type;
44  
45 5 local $_ = $self;
46  
47 5 ▶ my $value = $method
Branch: 2 branches
BranchTrueFalseTotal
$method ? : 3 2 5
$self->can('value') ? : 0 2 2
48 ? $self->$method(@args) : $self->can('value') ? $self->value : $self;
49  
50 5 return Venus::Type->new(value => $value);
51 }
52  
53 # EXPORTS
54  
55 sub EXPORT {
56 105 ▶ ['class', 'meta', 'reify', 'space', 'type']
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
57 }
58  
59 96 1;
60  
61  
62  
63 =head1 NAME
64  
65 Venus::Role::Reflectable - Reflectable Role
66  
67 =cut
68  
69 =head1 ABSTRACT
70  
71 Reflectable Role for Perl 5
72  
73 =cut
74  
75 =head1 SYNOPSIS
76  
77 package Example;
78  
79 use Venus::Class;
80  
81 with 'Venus::Role::Reflectable';
82  
83 sub test {
84 true
85 }
86  
87 package main;
88  
89 my $example = Example->new;
90  
91 # $example->space;
92  
93 =cut
94  
95 =head1 DESCRIPTION
96  
97 This package modifies the consuming package and provides methods for
98 introspecting the object and its underlying package.
99  
100 =cut
101  
102 =head1 METHODS
103  
104 This package provides the following methods:
105  
106 =cut
107  
108 =head2 class
109  
110 class() (string)
111  
112 The class method returns the class name for the given class or object.
113  
114 I<Since C<0.01>>
115  
116 =over 4
117  
118 =item class example 1
119  
120 # given: synopsis;
121  
122 my $class = $example->class;
123  
124 # "Example"
125  
126 =back
127  
128 =cut
129  
130 =head2 meta
131  
132 meta() (Venus::Meta)
133  
134 The meta method returns a L<Venus::Meta> object for the given object.
135  
136 I<Since C<1.23>>
137  
138 =over 4
139  
140 =item meta example 1
141  
142 # given: synopsis;
143  
144 my $meta = $example->meta;
145  
146 # bless({name => "Example"}, "Venus::Meta")
147  
148 =back
149  
150 =cut
151  
152 =head2 reify
153  
154 reify(string | coderef $code, any @args) (object)
155  
156 The reify method dispatches the method call or executes the callback and
157 returns the result as a value object.
158  
159 I<Since C<1.23>>
160  
161 =over 4
162  
163 =item reify example 1
164  
165 # given: synopsis
166  
167 package main;
168  
169 my $reify = $example->reify;
170  
171 # bless({}, "Example")
172  
173 =back
174  
175 =over 4
176  
177 =item reify example 2
178  
179 # given: synopsis
180  
181 package main;
182  
183 my $reify = $example->reify('class');
184  
185 # bless({value => "Example"}, "Venus::String")
186  
187 =back
188  
189 =over 4
190  
191 =item reify example 3
192  
193 # given: synopsis
194  
195 package main;
196  
197 my $reify = $example->reify('test');
198  
199 # bless({value => 1}, "Venus::Boolean")
200  
201 =back
202  
203 =cut
204  
205 =head2 space
206  
207 space() (Venus::Space)
208  
209 The space method returns a L<Venus::Space> object for the given object.
210  
211 I<Since C<0.01>>
212  
213 =over 4
214  
215 =item space example 1
216  
217 # given: synopsis;
218  
219 my $space = $example->space;
220  
221 # bless({ value => "Example" }, "Venus::Space")
222  
223 =back
224  
225 =cut
226  
227 =head2 type
228  
229 type(string | coderef $code, any @args) (Venus::Type)
230  
231 The type method dispatches the method call or executes the callback and returns
232 the result as a L<Venus::Type> object.
233  
234 I<Since C<0.01>>
235  
236 =over 4
237  
238 =item type example 1
239  
240 # given: synopsis;
241  
242 my $type = $example->type;
243  
244 # bless({ value => bless({}, "Example") }, "Venus::Type")
245  
246 =back
247  
248 =over 4
249  
250 =item type example 2
251  
252 # given: synopsis;
253  
254 my $type = $example->type('class');
255  
256 # bless({ value => "Example" }, "Venus::Type")
257  
258 =back
259  
260 =cut
261  
262 =head1 AUTHORS
263  
264 Awncorp, C<awncorp@cpan.org>
265  
266 =cut
267  
268 =head1 LICENSE
269  
270 Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>.
271  
272 This program is free software, you can redistribute it and/or modify it under
273 the terms of the Apache license version 2.0.
274  
275 =cut
« blib/lib/Venus/Role/Pluggable.pm ↑ Summary blib/lib/Venus/Role/Explainable.pm »