| 1 | package Venus::Role::Reflectable; | ||||||||||||||||||||
| 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 'with'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # METHODS | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2748 | ▶ | sub class { | ||||||||||||||||||
|
Subroutine
class: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 15 | 2748 | my ($self) = @_; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 2748 | ▶ | return ref($self) || $self; | ||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 2 | ▶ | sub clone { | ||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 21 | 2 | my ($self) = @_; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 2 | require Storable; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 2 | local $Storable::Deparse = 1; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 2 | local $Storable::Eval = 1; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2 | return Storable::dclone($self); | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 43 | ▶ | sub meta { | ||||||||||||||||||
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 33 | 43 | my ($self) = @_; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 43 | require Venus::Meta; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 43 | return Venus::Meta->new(name => $self->class); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 3 | ▶ | sub reify { | ||||||||||||||||||
|
Subroutine
reify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 41 | 3 | my ($self, $method, @args) = @_; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 3 | return $self->what($method, @args)->deduce; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | ▶ | sub space { | ||||||||||||||||||
|
Subroutine
space: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 47 | 1 | my ($self) = @_; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 1 | require Venus::Space; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | return Venus::Space->new($self->class); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 5 | ▶ | sub what { | ||||||||||||||||||
|
Subroutine
what: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 55 | 5 | my ($self, $method, @args) = @_; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 5 | require Venus::What; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 5 | local $_ = $self; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 5 | ▶ | my $value = $method | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 62 | ? $self->$method(@args) : $self->can('value') ? $self->value : $self; | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 5 | return Venus::What->new(value => $value); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # EXPORTS | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 129 | ▶ | sub EXPORT { | ||||||||||||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 70 | 129 | ['class', 'clone', 'meta', 'reify', 'space', 'what'] | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 119 | 1; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =head1 NAME | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Venus::Role::Reflectable - Reflectable Role | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =head1 ABSTRACT | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | Reflectable Role for Perl 5 | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =head1 SYNOPSIS | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | package Example; | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | use Venus::Class; | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | with 'Venus::Role::Reflectable'; | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | sub test { | ||||||||||||||||||||
| 98 | true | ||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | package main; | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | my $example = Example->new; | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | # $example->space; | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =head1 DESCRIPTION | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | This package modifies the consuming package and provides methods for | ||||||||||||||||||||
| 112 | introspecting the object and its underlying package. | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head1 METHODS | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | This package provides the following methods: | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head2 class | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | class() (string) | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | The class method returns the class name for the given class or object. | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | I<Since C<0.01>> | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | =over 4 | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =item class example 1 | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | # given: synopsis; | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | my $class = $example->class; | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | # "Example" | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =back | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head2 clone | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | clone() (object) | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | The clone method clones the invocant and returns the result. | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | I<Since C<4.15>> | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =over 4 | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =item clone example 1 | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | # given: synopsis | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | package main; | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | my $clone = $example->clone; | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | # bless(..., "Example") | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =back | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =head2 meta | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | meta() (Venus::Meta) | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | The meta method returns a L<Venus::Meta> object for the given object. | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | I<Since C<1.23>> | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =over 4 | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =item meta example 1 | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | # given: synopsis; | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | my $meta = $example->meta; | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | # bless({name => "Example"}, "Venus::Meta") | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | =back | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =head2 reify | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | reify(string | coderef $code, any @args) (object) | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | The reify method dispatches the method call or executes the callback and | ||||||||||||||||||||
| 195 | returns the result as a value object. | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | I<Since C<1.23>> | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | =over 4 | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | =item reify example 1 | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | # given: synopsis | ||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | package main; | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | my $reify = $example->reify; | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | # bless({}, "Example") | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | =back | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | =over 4 | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | =item reify example 2 | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | # given: synopsis | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | package main; | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | my $reify = $example->reify('class'); | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | # bless({value => "Example"}, "Venus::String") | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | =back | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | =over 4 | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | =item reify example 3 | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | # given: synopsis | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | package main; | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | my $reify = $example->reify('test'); | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | # bless({value => 1}, "Venus::Boolean") | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | =back | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | =cut | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | =head2 space | ||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | space() (Venus::Space) | ||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | The space method returns a L<Venus::Space> object for the given object. | ||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | I<Since C<0.01>> | ||||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | =over 4 | ||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | =item space example 1 | ||||||||||||||||||||
| 254 | |||||||||||||||||||||
| 255 | # given: synopsis; | ||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | my $space = $example->space; | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | # bless({ value => "Example" }, "Venus::Space") | ||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | =back | ||||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | =cut | ||||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | =head2 what | ||||||||||||||||||||
| 266 | |||||||||||||||||||||
| 267 | what(string | coderef $code, any @args) (Venus::What) | ||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | The what method dispatches the method call or executes the callback and returns | ||||||||||||||||||||
| 270 | the result as a L<Venus::What> object. | ||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | I<Since C<0.01>> | ||||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | =over 4 | ||||||||||||||||||||
| 275 | |||||||||||||||||||||
| 276 | =item what example 1 | ||||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | # given: synopsis; | ||||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | my $what = $example->what; | ||||||||||||||||||||
| 281 | |||||||||||||||||||||
| 282 | # bless({ value => bless({}, "Example") }, "Venus::What") | ||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | =back | ||||||||||||||||||||
| 285 | |||||||||||||||||||||
| 286 | =over 4 | ||||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | =item what example 2 | ||||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | # given: synopsis; | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | my $what = $example->what('class'); | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | # bless({ value => "Example" }, "Venus::What") | ||||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | =back | ||||||||||||||||||||
| 297 | |||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | =head1 AUTHORS | ||||||||||||||||||||
| 301 | |||||||||||||||||||||
| 302 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||
| 303 | |||||||||||||||||||||
| 304 | =cut | ||||||||||||||||||||
| 305 | |||||||||||||||||||||
| 306 | =head1 LICENSE | ||||||||||||||||||||
| 307 | |||||||||||||||||||||
| 308 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||
| 309 | |||||||||||||||||||||
| 310 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||
| 311 | the terms of the Apache license version 2.0. | ||||||||||||||||||||
| 312 | |||||||||||||||||||||
| 313 | =cut | ||||||||||||||||||||