blib/lib/Venus/Role/Stashable.pm

filter: Statementstmt 100% 22 / 22 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 33.3% 1 / 3 totaltotal 92.1% 35 / 38 CC 4 SCAR 5.9
CC
4
Cov
96%
stash
3.0
BUILD
2.0
BEGIN
1.0
CRAP 1.8
« blib/lib/Venus/Role/Accessible.pm ↑ Summary blib/lib/Venus/Task/Venus/Run.pm »
1 package Venus::Role::Stashable;
2  
3 1 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 1 ▶use Venus::Role 'mask';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ATTRIBUTES
13  
14 1 mask 'private';
15  
16 # BUILDERS
17  
18 4 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.1
Pod undocumented
19 4 my ($self, $data) = @_;
20  
21 4 ▶ $self->private({}) if !$self->private;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->private 4 0 4
22  
23 4 return $self;
24 };
25  
26 # METHODS
27  
28 3 ▶sub stash {
Subroutine stash: called CC=3 SCAR=11.0
Pod documented
29 3 my ($self, $key, $value) = @_;
30  
31 3 ▶ return $self->private if !exists $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[1] 1 2 3
32  
33 2 ▶ return $self->private->{$key} if !exists $_[2];
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[2] 1 1 2
34  
35 1 $self->private->{$key} = $value;
36  
37 1 return $value;
38 }
39  
40 # EXPORTS
41  
42 1 ▶sub EXPORT {
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
43 1 ['stash', 'private']
44 }
45  
46 1 1;
47  
48  
49  
50 =head1 NAME
51  
52 Venus::Role::Stashable - Stashable Role
53  
54 =cut
55  
56 =head1 ABSTRACT
57  
58 Stashable Role for Perl 5
59  
60 =cut
61  
62 =head1 SYNOPSIS
63  
64 package Example;
65  
66 use Venus::Class;
67  
68 with 'Venus::Role::Stashable';
69  
70 attr 'test';
71  
72 package main;
73  
74 my $example = Example->new(test => time);
75  
76 # $example->stash;
77  
78 =cut
79  
80 =head1 DESCRIPTION
81  
82 This package modifies the consuming package and provides methods for stashing
83 data within the object. This role differs from L<Venus::Role::Encaseable> in
84 that it obsures the stash but its data is easily accessible without getters and
85 setters, whereas Encaseable provides getters and setters to help obscure the
86 private instance data.
87  
88 =cut
89  
90 =head1 METHODS
91  
92 This package provides the following methods:
93  
94 =cut
95  
96 =head2 stash
97  
98 stash(any $key, any $value) (any)
99  
100 The stash method is used to fetch and stash named values associated with the
101 object. Calling this method without arguments returns all values.
102  
103 I<Since C<0.01>>
104  
105 =over 4
106  
107 =item stash example 1
108  
109 package main;
110  
111 my $example = Example->new(test => time);
112  
113 my $stash = $example->stash;
114  
115 # {}
116  
117 =back
118  
119 =over 4
120  
121 =item stash example 2
122  
123 package main;
124  
125 my $example = Example->new(test => time);
126  
127 my $stash = $example->stash('test', {1..4});
128  
129 # { 1 => 2, 3 => 4 }
130  
131 =back
132  
133 =over 4
134  
135 =item stash example 3
136  
137 package main;
138  
139 my $example = Example->new(test => time);
140  
141 my $stash = $example->stash('test');
142  
143 # undef
144  
145 =back
146  
147 =cut
148  
149 =head1 AUTHORS
150  
151 Awncorp, C<awncorp@cpan.org>
152  
153 =cut
154  
155 =head1 LICENSE
156  
157 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
158  
159 This program is free software, you can redistribute it and/or modify it under
160 the terms of the Apache license version 2.0.
161  
162 =cut
« blib/lib/Venus/Role/Accessible.pm ↑ Summary blib/lib/Venus/Task/Venus/Run.pm »