File Coverage

blib/lib/MyCPAN/Indexer/Notes.pm
Criterion Covered Total %
statement 9 32 28.1
branch 0 6 0.0
condition n/a
subroutine 3 12 25.0
pod 9 9 100.0
total 21 59 35.5


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