| 1 | package Venus::Sealed; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.018; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Venus::Class 'with'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | with 'Venus::Role::Buildable'; | |||||||||||||||||||||||||||
| 11 | 3 | with 'Venus::Role::Proxyable'; | |||||||||||||||||||||||||||
| 12 | 3 | with 'Venus::Role::Tryable'; | |||||||||||||||||||||||||||
| 13 | 3 | with 'Venus::Role::Throwable'; | |||||||||||||||||||||||||||
| 14 | 3 | with 'Venus::Role::Catchable'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # BUILDERS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub build_arg { | ||||||||||||||||||||||||||||
| 19 | 5 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_arg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | return { | ||||||||||||||||||||||||||||
| 22 | 5 | value => $data, | |||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub build_args { | ||||||||||||||||||||||||||||
| 27 | 53 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_args: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 53 | ▶ | if (not(keys %$data == 1 && exists $data->{value})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
keys %$data == 1 and exists $data->{"value"}
MC/DC50%1/2
keys %$data == 1 and exists $data->{"value"}
keys %$data == 1
exists $data->{"value"}
Truth table66%2/3
A and B
A= keys %$data == 1B= exists $data->{"value"}
| |||||||||||||||||||||||||||||
| 30 | 13 | ▶ | $data = (exists $data->{value}) ? {value => $data->{value}} : {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 53 | require Storable; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 53 | $data = Storable::dclone($data); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | my $state = { | ||||||||||||||||||||||||||||
| 38 | 53 | ▶ | (exists $data->{value} ? (value => $data->{value}) : ()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 53 | my $subs = { | |||||||||||||||||||||||||||
| 42 | map +($_, $self->can($_)), grep /^__\w+$/, $self->meta->subs, | ||||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | my $scope = sub { | ||||||||||||||||||||||||||||
| 46 | 73 | ▶ | my ($self, $name, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 73 | ▶ | return if !$name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 73 | my $method = "__$name"; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 73 | ▶ | return if !$subs->{$method}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 73 | return $subs->{$method}->($self, $data, $state, @args); | |||||||||||||||||||||||||||
| 55 | 53 | }; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | return { | ||||||||||||||||||||||||||||
| 58 | 53 | scope => $scope, | |||||||||||||||||||||||||||
| 59 | }; | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub build_self { | ||||||||||||||||||||||||||||
| 63 | 53 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_self: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 53 | return $self; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub build_proxy { | ||||||||||||||||||||||||||||
| 69 | 73 | ▶ | my ($self, $package, $name, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_proxy: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 73 | my $method = $self->can("__$name"); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 73 | ▶ | if (!$method && ref $method ne 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $method and ref $method ne "CODE"
MC/DC0%0/2
not $method and ref $method ne "CODE"
not $method
ref $method ne "CODE"
Truth table33%1/3
not(A) and B
A= not $methodB= ref $method ne "CODE"
| |||||||||||||||||||||||||||||
| 74 | 0 | return undef; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | return sub { | ||||||||||||||||||||||||||||
| 78 | 73 | ▶ | return $self->{scope}->($self, $name, @args); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | 73 | }; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # METHODS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub __get { | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | my ($self, $init, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__get: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | return $data->{value}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub __set { | ||||||||||||||||||||||||||||
| 91 | 1 | ▶ | my ($self, $init, $data, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__set: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | return $data->{value} = $value; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | 1; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 NAME | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Venus::Sealed - Sealed Class | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | Sealed Class for Perl 5 | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | package main; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | use Venus::Sealed; | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | my $sealed = Venus::Sealed->new('012345'); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # $sealed->get; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # '012345' | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | This package provides a mechanism for sealing object and restricting and/or | ||||||||||||||||||||||||||||
| 129 | preventing access to the underlying data structures. This package can be used | ||||||||||||||||||||||||||||
| 130 | directly but is meant to be subclassed. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 INTEGRATES | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | This package integrates behaviors from: | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | L<Venus::Role::Buildable> | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | L<Venus::Role::Catchable> | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | L<Venus::Role::Proxyable> | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | L<Venus::Role::Throwable> | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | L<Venus::Role::Tryable> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =cut | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 METHODS | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | This package provides the following methods: | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =head2 get | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | get(any @args) (any) | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | The get method can be used directly to get the sealed value set during | ||||||||||||||||||||||||||||
| 161 | instantiation, but is meant to be overridden in a subclass to further control | ||||||||||||||||||||||||||||
| 162 | access to the underlying data. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | I<Since C<3.55>> | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =over 4 | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =item get example 1 | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # given: synopsis | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | package main; | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | my $get = $sealed->get; | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # "012345" | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =back | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =over 4 | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =item get example 2 | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | package Example; | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | use Venus::Class; | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | base 'Venus::Sealed'; | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | sub __get { | ||||||||||||||||||||||||||||
| 191 | my ($self, $init, $data) = @_; | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | return $data->{value}; | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | sub __set { | ||||||||||||||||||||||||||||
| 197 | my ($self, $init, $data, $value) = @_; | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | return $data->{value} = $value; | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | package main; | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | my $sealed = Example->new("012345"); | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | my $get = $sealed->get; | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # "012345" | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =back | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =cut | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head2 set | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | set(any @args) (any) | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | The set method can be used directly to set the sealed value set during | ||||||||||||||||||||||||||||
| 219 | instantiation, but is meant to be overridden in a subclass to further control | ||||||||||||||||||||||||||||
| 220 | access to the underlying data. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | I<Since C<3.55>> | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =over 4 | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =item set example 1 | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # given: synopsis | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | package main; | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | my $set = $sealed->set("098765"); | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # "098765" | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =back | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =over 4 | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =item set example 2 | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | package Example; | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | use Venus::Class; | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | base 'Venus::Sealed'; | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | sub __get { | ||||||||||||||||||||||||||||
| 249 | my ($self, $init, $data) = @_; | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | return $data->{value}; | ||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | sub __set { | ||||||||||||||||||||||||||||
| 255 | my ($self, $init, $data, $value) = @_; | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | return $data->{value} = $value; | ||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | package main; | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | my $sealed = Example->new("012345"); | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | my $set = $sealed->set("098765"); | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # "098765" | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =back | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | =cut | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 283 | the terms of the Apache license version 2.0. | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | =cut | ||||||||||||||||||||||||||||