| 1 | package List::Filter::Storage::MEM; | ||||||||||||
| 2 | # use base qw( Class::Base ); | ||||||||||||
| 3 | 1 | ▶ | use base qw( List::Filter::StorageBase ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | =head1 NAME | ||||||||||||
| 6 | |||||||||||||
| 7 | List::Filter::Storage::MEM - filter storage in memory | ||||||||||||
| 8 | |||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||
| 10 | |||||||||||||
| 11 | use List::Filter::Storage::MEM; | ||||||||||||
| 12 | my $ffpsm = List::Filter::Storage::MEM->new(); | ||||||||||||
| 13 | |||||||||||||
| 14 | # This is a plugin, not intended for direct use. | ||||||||||||
| 15 | # See: List:Filter:Storage | ||||||||||||
| 16 | |||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||
| 18 | |||||||||||||
| 19 | List::Filter::Storage::MEM, is a Plug-in to use for | ||||||||||||
| 20 | "storing" List::Filter filters in memory, so that they can be | ||||||||||||
| 21 | recalled using the List::Filter::Storage interface that | ||||||||||||
| 22 | scans through multiple storage locations. | ||||||||||||
| 23 | |||||||||||||
| 24 | The filter_data structure may be passed in as the "connect_to" | ||||||||||||
| 25 | parameter, or one will be created internally if one has not been | ||||||||||||
| 26 | passed in. This may be added to with the "save" method. | ||||||||||||
| 27 | The entire structure can be extracted with the "filter_data" | ||||||||||||
| 28 | accessor, or (more typically) filter's may be looked up by name, | ||||||||||||
| 29 | using the "lookup" method. | ||||||||||||
| 30 | |||||||||||||
| 31 | =head2 METHODS | ||||||||||||
| 32 | |||||||||||||
| 33 | =cut | ||||||||||||
| 34 | |||||||||||||
| 35 | 1 | ▶ | use 5.8.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | 1 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 40 | 1 | ▶ | use Hash::Util qw( lock_keys unlock_keys ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 41 | |||||||||||||
| 42 | 1 | our $VERSION = '0.01'; | |||||||||||
| 43 | |||||||||||||
| 44 | =head2 initialization code | ||||||||||||
| 45 | |||||||||||||
| 46 | =over | ||||||||||||
| 47 | |||||||||||||
| 48 | =item new | ||||||||||||
| 49 | |||||||||||||
| 50 | Instantiates a new List::Filter::Profile object. | ||||||||||||
| 51 | |||||||||||||
| 52 | Takes an optional hashref as an argument, with named fields | ||||||||||||
| 53 | identical to the names of the object attributes. | ||||||||||||
| 54 | |||||||||||||
| 55 | With no arguments, the newly created filter will be empty. | ||||||||||||
| 56 | |||||||||||||
| 57 | =cut | ||||||||||||
| 58 | |||||||||||||
| 59 | # Note: "new" (inherited from Class::Base) | ||||||||||||
| 60 | # calls the following "init" routine automatically. | ||||||||||||
| 61 | |||||||||||||
| 62 | =item init | ||||||||||||
| 63 | |||||||||||||
| 64 | Initialize object attributes and then lock them down to prevent | ||||||||||||
| 65 | accidental creation of new ones. | ||||||||||||
| 66 | |||||||||||||
| 67 | Note: there is no leading underscore on name "init", though it's | ||||||||||||
| 68 | arguably an "internal" routine (i.e. not likely to be of use to | ||||||||||||
| 69 | client code). | ||||||||||||
| 70 | |||||||||||||
| 71 | =cut | ||||||||||||
| 72 | |||||||||||||
| 73 | 34 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 74 | 34 | my $self = shift; | |||||||||||
| 75 | 34 | my $args = shift; | |||||||||||
| 76 | 34 | unlock_keys( %{ $self } ); | |||||||||||
| 77 | |||||||||||||
| 78 | 34 | $self->SUPER::init( $args ); # uncomment if this is a child class | |||||||||||
| 79 | |||||||||||||
| 80 | 34 | ▶ | my $filter_data = $args->{connect_to} || {}; | ||||||||||
|
Condition100%2/2
$args->{'connect_to'} || {}
MC/DC100%1/1
$args->{'connect_to'} || {}
$args->{'connect_to'}
Truth table100%2/2
A
A= $args->{'connect_to'}
| |||||||||||||
| 81 | 34 | $self->set_filter_data( $filter_data ); | |||||||||||
| 82 | |||||||||||||
| 83 | 34 | lock_keys( %{ $self } ); | |||||||||||
| 84 | 34 | return $self; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | =item save | ||||||||||||
| 88 | |||||||||||||
| 89 | Given a filter "saves" it in memory. | ||||||||||||
| 90 | |||||||||||||
| 91 | Returns the ref to the filter object. | ||||||||||||
| 92 | |||||||||||||
| 93 | =cut | ||||||||||||
| 94 | |||||||||||||
| 95 | 3 | ▶ | sub save { | ||||||||||
|
Subroutine
save: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 96 | 3 | my $self = shift; | |||||||||||
| 97 | 3 | my $filter = shift; | |||||||||||
| 98 | |||||||||||||
| 99 | # convert $filter object into a data structure, | ||||||||||||
| 100 | |||||||||||||
| 101 | 3 | my $filter_name = $filter->name; | |||||||||||
| 102 | |||||||||||||
| 103 | 3 | my $method = $filter->method; | |||||||||||
| 104 | 3 | my $description = $filter->description; | |||||||||||
| 105 | 3 | my $terms = $filter->terms; | |||||||||||
| 106 | 3 | my $modifiers = $filter->modifiers; | |||||||||||
| 107 | |||||||||||||
| 108 | 3 | my $filter_href = { method => $method, | |||||||||||
| 109 | description => $description, | ||||||||||||
| 110 | terms => $terms, | ||||||||||||
| 111 | modifiers => $modifiers, | ||||||||||||
| 112 | }; | ||||||||||||
| 113 | |||||||||||||
| 114 | # add it to the internal stash (replaces any existing one of same name) | ||||||||||||
| 115 | 3 | my $filter_data = $self->filter_data; | |||||||||||
| 116 | 3 | $filter_data->{ $filter_name } = $filter_href; | |||||||||||
| 117 | |||||||||||||
| 118 | 3 | return $filter; | |||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | |||||||||||||
| 122 | =item lookup | ||||||||||||
| 123 | |||||||||||||
| 124 | =cut | ||||||||||||
| 125 | |||||||||||||
| 126 | # Note: this is *identical* to the code in (the original) YAML.pm | ||||||||||||
| 127 | 3 | ▶ | sub lookup { | ||||||||||
|
Subroutine
lookup: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 128 | 3 | my $self = shift; | |||||||||||
| 129 | 3 | my $name = shift; | |||||||||||
| 130 | |||||||||||||
| 131 | 3 | my $filter_data = $self->filter_data; | |||||||||||
| 132 | |||||||||||||
| 133 | 3 | my $filter; | |||||||||||
| 134 | 3 | ▶ | if ( my $filter_href = $filter_data->{ $name } ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 135 | |||||||||||||
| 136 | # convert this data into a filter object. | ||||||||||||
| 137 | 3 | my $terms = $filter_href->{terms}; | |||||||||||
| 138 | 3 | my $method = $filter_href->{method}; | |||||||||||
| 139 | 3 | my $description = $filter_href->{description}; | |||||||||||
| 140 | 3 | my $modifiers = $filter_href->{modifiers}; | |||||||||||
| 141 | |||||||||||||
| 142 | 3 | my $filter_class = $self->define_filter_class; | |||||||||||
| 143 | 3 | $filter = $filter_class->new( | |||||||||||
| 144 | { name => $name, | ||||||||||||
| 145 | terms => $terms, | ||||||||||||
| 146 | method => $method, | ||||||||||||
| 147 | description => $description, | ||||||||||||
| 148 | modifiers => $modifiers, | ||||||||||||
| 149 | } ); | ||||||||||||
| 150 | |||||||||||||
| 151 | } | ||||||||||||
| 152 | 3 | return $filter; | |||||||||||
| 153 | } | ||||||||||||
| 154 | |||||||||||||
| 155 | |||||||||||||
| 156 | |||||||||||||
| 157 | =item list_filters | ||||||||||||
| 158 | |||||||||||||
| 159 | Returns a list of all avaliable named filters. | ||||||||||||
| 160 | |||||||||||||
| 161 | =cut | ||||||||||||
| 162 | |||||||||||||
| 163 | 2 | ▶ | sub list_filters { | ||||||||||
|
Subroutine
list_filters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 164 | 2 | my $self = shift; | |||||||||||
| 165 | 2 | my $filter_data = $self->filter_data; | |||||||||||
| 166 | 2 | my @names = keys (%{ $filter_data }); | |||||||||||
| 167 | 2 | return \@names; | |||||||||||
| 168 | } | ||||||||||||
| 169 | |||||||||||||
| 170 | |||||||||||||
| 171 | =back | ||||||||||||
| 172 | |||||||||||||
| 173 | =head2 special accessors (access the "extra" namespace) | ||||||||||||
| 174 | |||||||||||||
| 175 | =over | ||||||||||||
| 176 | |||||||||||||
| 177 | =item filter_data | ||||||||||||
| 178 | |||||||||||||
| 179 | Getter for object attribute filter_data | ||||||||||||
| 180 | |||||||||||||
| 181 | =cut | ||||||||||||
| 182 | |||||||||||||
| 183 | 8 | ▶ | sub filter_data { | ||||||||||
|
Subroutine
filter_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 184 | 8 | my $self = shift; | |||||||||||
| 185 | 8 | my $filter_data = $self->extra->{ filter_data }; | |||||||||||
| 186 | |||||||||||||
| 187 | 8 | return $filter_data; | |||||||||||
| 188 | } | ||||||||||||
| 189 | |||||||||||||
| 190 | =item set_filter_data | ||||||||||||
| 191 | |||||||||||||
| 192 | Setter for object attribute set_filter_data | ||||||||||||
| 193 | |||||||||||||
| 194 | =cut | ||||||||||||
| 195 | |||||||||||||
| 196 | 42 | ▶ | sub set_filter_data { | ||||||||||
|
Subroutine
set_filter_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 197 | 42 | my $self = shift; | |||||||||||
| 198 | 42 | my $filter_data = shift; | |||||||||||
| 199 | 42 | $self->extra->{ filter_data } = $filter_data; | |||||||||||
| 200 | 42 | return $filter_data; | |||||||||||
| 201 | } | ||||||||||||
| 202 | |||||||||||||
| 203 | |||||||||||||
| 204 | 1 | 1; | |||||||||||
| 205 | |||||||||||||
| 206 | =back | ||||||||||||
| 207 | |||||||||||||
| 208 | =head2 basic accessors (defined in L<List::Filter::StorageBase>); | ||||||||||||
| 209 | |||||||||||||
| 210 | =over | ||||||||||||
| 211 | |||||||||||||
| 212 | =item connect_to | ||||||||||||
| 213 | |||||||||||||
| 214 | Getter for object attribute connect_to | ||||||||||||
| 215 | |||||||||||||
| 216 | =item set_connect_to | ||||||||||||
| 217 | |||||||||||||
| 218 | Setter for object attribute set_connect_to | ||||||||||||
| 219 | |||||||||||||
| 220 | =item owner | ||||||||||||
| 221 | |||||||||||||
| 222 | Getter for object attribute owner | ||||||||||||
| 223 | |||||||||||||
| 224 | =cut | ||||||||||||
| 225 | |||||||||||||
| 226 | =item set_owner | ||||||||||||
| 227 | |||||||||||||
| 228 | Setter for object attribute set_owner | ||||||||||||
| 229 | |||||||||||||
| 230 | =cut | ||||||||||||
| 231 | |||||||||||||
| 232 | =item password | ||||||||||||
| 233 | |||||||||||||
| 234 | Getter for object attribute password | ||||||||||||
| 235 | |||||||||||||
| 236 | =cut | ||||||||||||
| 237 | |||||||||||||
| 238 | =item set_password | ||||||||||||
| 239 | |||||||||||||
| 240 | Setter for object attribute set_password | ||||||||||||
| 241 | |||||||||||||
| 242 | =cut | ||||||||||||
| 243 | |||||||||||||
| 244 | =item attributes | ||||||||||||
| 245 | |||||||||||||
| 246 | Getter for object attribute attributes | ||||||||||||
| 247 | |||||||||||||
| 248 | =item set_attributes | ||||||||||||
| 249 | |||||||||||||
| 250 | Setter for object attribute set_attributes | ||||||||||||
| 251 | |||||||||||||
| 252 | =item extra | ||||||||||||
| 253 | |||||||||||||
| 254 | Getter for object attribute extra | ||||||||||||
| 255 | |||||||||||||
| 256 | =item set_extra | ||||||||||||
| 257 | |||||||||||||
| 258 | Setter for object attribute set_extra | ||||||||||||
| 259 | |||||||||||||
| 260 | =back | ||||||||||||
| 261 | |||||||||||||
| 262 | =head1 SEE ALSO | ||||||||||||
| 263 | |||||||||||||
| 264 | L<List::Filter> | ||||||||||||
| 265 | |||||||||||||
| 266 | =head1 AUTHOR | ||||||||||||
| 267 | |||||||||||||
| 268 | Joseph Brenner, E<lt>doom@kzsu.stanford.eduE<gt>, | ||||||||||||
| 269 | 18 May 2007 | ||||||||||||
| 270 | |||||||||||||
| 271 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 272 | |||||||||||||
| 273 | Copyright (C) 2007 by Joseph Brenner | ||||||||||||
| 274 | |||||||||||||
| 275 | This library is free software; you can redistribute it and/or modify | ||||||||||||
| 276 | it under the same terms as Perl itself, either Perl version 5.8.2 or, | ||||||||||||
| 277 | at your option, any later version of Perl 5 you may have available. | ||||||||||||
| 278 | |||||||||||||
| 279 | =head1 BUGS | ||||||||||||
| 280 | |||||||||||||
| 281 | None reported... yet. | ||||||||||||
| 282 | |||||||||||||
| 283 | =cut | ||||||||||||