blib/lib/Venus/Role/Stashable.pm

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