| 1 | package List::Filter::Transform::Library::FileSystem; | ||||||||||||||||||||
| 2 | 1 | ▶ | use base qw( Class::Base ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | List::Filter::Transform::Library::FileSystem - transforms for working with unix file listings | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # This is a plugin, not intended for direct use. | ||||||||||||||||||||
| 12 | # See: List::Filter::Storage::CODE | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | A library of standard List::Filter "transforms" for working with | ||||||||||||||||||||
| 17 | unix file listings. | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | See L<List::Filter::Transform::Library::Documentation> | ||||||||||||||||||||
| 20 | for information about the transforms defined by this module. | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head2 filters | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | The following is a (most likely partialy) listing of named | ||||||||||||||||||||
| 25 | filters are defined by this module. | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | Note that all follow the "leading colon" naming convention. | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =over | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | =item :dwim_upcaret | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | Returns a transform to be used on regexps that are intended | ||||||||||||||||||||
| 34 | to pick entries out of unix file system listings: | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | It converts a leading "^" in a regexp into a "\b", except when | ||||||||||||||||||||
| 37 | it looks like you really meant to match the beginning of the | ||||||||||||||||||||
| 38 | string, which in a file listing is typically relatively uninteresting, | ||||||||||||||||||||
| 39 | e.g. | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | /usr/share/bin/this | ||||||||||||||||||||
| 42 | /usr/share/bin/that | ||||||||||||||||||||
| 43 | /usr/share/bin/theother | ||||||||||||||||||||
| 44 | ... | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =back | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1 | ▶ | use 5.8.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 1 | ▶ | use Hash::Util qw( lock_keys unlock_keys ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||
| 58 | 1 | my $DEBUG = 0; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =head2 METHODS | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =over | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =item new | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | Instantiates a new List::Filter::Profile object. | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | Takes an optional hashref as an argument, with named fields | ||||||||||||||||||||
| 69 | identical to the names of the object attributes. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | With no arguments, the newly created profile will be empty. | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # Note: "new" (inherited from Class::Base) | ||||||||||||||||||||
| 76 | # calls the following "init" routine automatically. | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =item init | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Initialize object attributes and then lock them down to prevent | ||||||||||||||||||||
| 81 | accidental creation of new ones. | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | Note: there is no leading underscore on name "init", though it's | ||||||||||||||||||||
| 84 | arguably an "internal" routine (i.e. not likely to be of use to | ||||||||||||||||||||
| 85 | client code). | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 2 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 90 | 2 | my $self = shift; | |||||||||||||||||||
| 91 | 2 | my $args = shift; | |||||||||||||||||||
| 92 | 2 | unlock_keys( %{ $self } ); | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 2 | my $storage_handler = List::Filter::Storage->new( storage => | |||||||||||||||||||
| 95 | { format => 'MEM', } ); | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | # define new attributes | ||||||||||||||||||||
| 98 | my $attributes = { | ||||||||||||||||||||
| 99 | 2 | ▶ | storage_handler => $args->{ storage_handler} || $storage_handler, | ||||||||||||||||||
|
Condition33%1/3
$args->{'storage_handler'} || $storage_handler
MC/DC0%0/2
$args->{'storage_handler'} || $storage_handler
$args->{'storage_handler'}
$storage_handler
Truth table33%1/3
A || B
A= $args->{'storage_handler'}B= $storage_handler
| |||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | # add attributes to object | ||||||||||||||||||||
| 103 | 2 | my @fields = (keys %{ $attributes }); | |||||||||||||||||||
| 104 | 2 | @{ $self }{ @fields } = @{ $attributes }{ @fields }; # hash slice | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 2 | lock_keys( %{ $self } ); | |||||||||||||||||||
| 107 | 2 | return $self; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =item define_filters_href | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 2 | ▶ | sub define_filters_href { | ||||||||||||||||||
|
Subroutine
define_filters_href: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 115 | 2 | my $self = shift; | |||||||||||||||||||
| 116 | 2 | my $transforms = | |||||||||||||||||||
| 117 | { | ||||||||||||||||||||
| 118 | ':dwim_upcaret' => | ||||||||||||||||||||
| 119 | { | ||||||||||||||||||||
| 120 | 'description' => "leading '^' converted to \\b, unless it's '^/' or '^~'", | ||||||||||||||||||||
| 121 | 'method' => 'sequential', | ||||||||||||||||||||
| 122 | 'terms' => | ||||||||||||||||||||
| 123 | [ | ||||||||||||||||||||
| 124 | [ | ||||||||||||||||||||
| 125 | ' ^ \^ (?![/~]) | (?<=\|) \^ (?![/~]) ', | ||||||||||||||||||||
| 126 | 'xg', | ||||||||||||||||||||
| 127 | '\\b'], | ||||||||||||||||||||
| 128 | ], | ||||||||||||||||||||
| 129 | 'modifiers' => "x", | ||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||
| 133 | 2 | return $transforms; | |||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =back | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =head2 basic setters and getters | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =over | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =item storage_handler | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Getter for object attribute storage_handler | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =cut | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 0 | ▶ | sub storage_handler { | ||||||||||||||||||
|
Subroutine
storage_handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||
| 152 | 0 | my $storage_handler = $self->{ storage_handler }; | |||||||||||||||||||
| 153 | 0 | return $storage_handler; | |||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | =item set_storage_handler | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | Setter for object attribute set_storage_handler | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 0 | ▶ | sub set_storage_handler { | ||||||||||||||||||
|
Subroutine
set_storage_handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 163 | 0 | my $self = shift; | |||||||||||||||||||
| 164 | 0 | my $storage_handler = shift; | |||||||||||||||||||
| 165 | 0 | $self->{ storage_handler } = $storage_handler; | |||||||||||||||||||
| 166 | 0 | return $storage_handler; | |||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 1 | 1; | |||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =back | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | =head1 SEE ALSO | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | L<List::Filter> | ||||||||||||||||||||
| 178 | L<List::Filter::Project> | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | L<List::Filter::App::Relate> | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =head1 AUTHOR | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | Joseph Brenner, E<lt>doom@kzsu.stanford.eduE<gt>, | ||||||||||||||||||||
| 185 | 24 May 2007 | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | Copyright (C) 2007 by Joseph Brenner | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 192 | it under the same terms as Perl itself, either Perl version 5.8.2 or, | ||||||||||||||||||||
| 193 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | =head1 BUGS | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | None reported... yet. | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | =cut | ||||||||||||||||||||