Indexer/Notes.pm

filter: Statementstmt 32.3% 11 / 34 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 3 / 12 Podpod 100% 9 / 9 totaltotal 37.7% 23 / 61 CC 4 SCAR 12.2
CC
4
Cov
28%
push_onto_note
6.0
unshift_onto_note
6.0
set_note_unless_defined
6.0
CRAP 3.4
« Indexer/Dispatcher/Serial.pm ↑ Summary Indexer/Interface/Curses.pm »
1 package MyCPAN::Indexer::Notes;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '1.282';
8  
9 =encoding utf8
10  
11 =head1 NAME
12  
13 MyCPAN::Indexer::Notes - Tiny class for MyCPAN component note passing
14  
15 =head1 SYNOPSIS
16  
17 Use in the coordinator object. This isn't really for the public.
18  
19 =head1 DESCRIPTION
20  
21 This is a scratchpad for the C<MyCPAN::Indexer> components. As a component
22 does part of its job, it can leave notes that other components can inspect
23 and use.
24  
25 This is a low-level implementation, so it's stupid about the keys and
26 values that the components might use. It doesn't attempt to validate or
27 constrain the notes in any way. It can, however, act as a base class for
28 a custom notes class.
29  
30 =cut
31  
32 =head2 Methods
33  
34 =over 4
35  
36 =item new
37  
38 Create a new notes object. This is really just a fancy hash. You probably
39 shouldn't call this yourself unless you are working in the coordinator
40 object.
41  
42 =cut
43  
44 sub new
45 0 ▶ {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
46 0 my( $class ) = @_;
47  
48 0 my $self = bless {}, $class;
49  
50 0 $self;
51 }
52  
53 =item get_note( NOTE )
54  
55 Get the note named C<NOTE>. This could be anything that was set: a
56 string, reference, and so on.
57  
58 =cut
59  
60 0 ▶sub get_note { $_[0]->{$_[1]} }
Subroutine get_note: not called CC=1 SCAR=6.9
Pod documented
61  
62 =item set_note( NOTE, SOMETHING )
63  
64 Set the note named C<NOTE>. This could be anything you like: a string,
65 reference, and so on.
66  
67 =cut
68  
69 0 ▶sub set_note { $_[0]->{$_[1]} = $_[2] }
Subroutine set_note: not called CC=1 SCAR=6.9
Pod documented
70  
71 =back
72  
73 =head2 Convenience methods
74  
75 This saves you the hassle of getting the value with C<get_note>,
76 changing it, and saving the new value with C<set_note>.
77  
78 =over 4
79  
80 =item increment_note( NOTE )
81  
82 Increase the value of NOTE by one. Returns the previous value of NOTE.
83  
84 =cut
85  
86 sub increment_note
87 0 ▶ {
Subroutine increment_note: not called CC=1 SCAR=6.9
Pod documented
88 0 my $value = $_[0]->get_note( $_[1] );
89 0 $_[0]->set_note( $_[1], $value + 1 );
90 0 $value;
91 }
92  
93 =item decrement_note( NOTE )
94  
95 Decrease the value of NOTE by one. Returns the previous value of NOTE.
96  
97 =cut
98  
99 sub decrement_note
100 0 ▶ {
Subroutine decrement_note: not called CC=1 SCAR=6.9
Pod documented
101 0 my $value = $_[0]->get_note( $_[1] );
102 0 $_[0]->set_note( $_[1], $value - 1 );
103 0 $value;
104 }
105  
106 =item push_onto_note( NOTE, LIST )
107  
108 Add a value onto the end of the array reference value for NOTE.
109  
110 =cut
111  
112 sub push_onto_note
113 0 ▶ {
Subroutine push_onto_note: not called CC=2 SCAR=17.9
Pod documented
114 0 my( $self, $key, @list ) = @_;
115  
116 0 my $ref = $self->get_note( $key );
117 0 ▶ croak( "Value for note [$key] is not an array reference" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ref eq ref [] 0 0 0
118 unless ref $ref eq ref [];
119 0 push @$ref, @list;
120 }
121  
122 =item unshift_onto_note( NOTE, LIST )
123  
124 Add a value onto the front of the array reference value for NOTE.
125  
126 =cut
127  
128 sub unshift_onto_note
129 0 ▶ {
Subroutine unshift_onto_note: not called CC=2 SCAR=17.9
Pod documented
130 0 my( $self, $key, @list ) = @_;
131  
132 0 my $ref = $self->get_note( $key );
133 0 ▶ croak( "Value for note [$key] is not an array reference" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ref eq ref [] 0 0 0
134 unless ref $ref eq ref [];
135 0 unshift @$ref, @list;
136 }
137  
138 =item get_note_list_element( NOTE, INDEX )
139  
140 Return the list element at INDEX for the array reference stored in NOTE.
141  
142 =cut
143  
144 sub get_note_list_element
145 0 ▶ {
Subroutine get_note_list_element: not called CC=1 SCAR=6.9
Pod documented
146 0 $_[0]->get_note( $_[1] )->[ $_[2] ]
147 }
148  
149 =item set_note_unless_defined( NOTE, VALUE )
150  
151 Set the VALUE for NOTE unless NOTE already has a defined value. Returns
152 the current value if it is already defined.
153  
154 =cut
155  
156 sub set_note_unless_defined
157 0 ▶ {
Subroutine set_note_unless_defined: not called CC=2 SCAR=17.9
Pod documented
158 0 my $value = $_[0]->get_note( $_[1] );
159 0 ▶ return $value if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
160  
161 0 $_[0]->set_note( $_[1], $_[2] );
162 }
163  
164 =back
165  
166 =head1 SOURCE AVAILABILITY
167  
168 This code is in Github:
169  
170 git://github.com/briandfoy/mycpan-indexer.git
171  
172 =head1 AUTHOR
173  
174 brian d foy, C<< <bdfoy@cpan.org> >>
175  
176 =head1 COPYRIGHT AND LICENSE
177  
178 Copyright © 2008-2018, brian d foy <bdfoy@cpan.org>. All rights reserved.
179  
180 You may redistribute this under the terms of the Artistic License 2.0.
181  
182 =cut
183  
184 1 1;
« Indexer/Dispatcher/Serial.pm ↑ Summary Indexer/Interface/Curses.pm »