blib/lib/POE/Filter/Map.pm

filter: Statementstmt 100% 56 / 56 Branchbran 90.0% 27 / 30 Conditioncond 80.0% 16 / 20 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 90.3% 121 / 134 CC 23 SCAR 20.8
CC
23
Cov
93%
new
14.1
modify
7.1
get_one_start
2.0
CRAP 8.0
« blib/lib/POE/Resource/Events.pm ↑ Summary blib/lib/POE/Filter/Grep.pm »
1 # 2001/01/25 shizukesa@pobox.com
2  
3 package POE::Filter::Map;
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use POE::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 $VERSION = '1.370'; # NOTE - Should be #.### (three decimal places)
10 4 @ISA = qw(POE::Filter);
11  
12 4 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub BUFFER () { 0 }
15 sub CODEGET () { 1 }
16 sub CODEPUT () { 2 }
17  
18 sub FIRST_UNUSED () { 3 } # First unused $self offset.
19  
20 4 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 our @EXPORT_OK = qw( FIRST_UNUSED );
22  
23  
24 #------------------------------------------------------------------------------
25  
26 12 ▶sub new {
Subroutine new: called CC=14 SCAR=26.4
Pod documented
27 12 my $type = shift;
28 12 ▶ croak "$type must be given an even number of parameters" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 1 11 12
29 11 my %params = @_;
30  
31 croak "$type requires a Code or both Get and Put parameters" unless (
32 defined($params{Code}) or
33 11 ▶ (defined($params{Get}) and defined($params{Put}))
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"Code"} or defined $params{"Get"} and defined $params{"Put"} 3 8 11
Condition100%6/6
defined $params{"Code"} or defined $params{"Get"} and defined $params{"Put"}
l!l&&r!l&&!r
353
defined $params{"Get"} and defined $params{"Put"}
!ll&&!rl&&r
215
MC/DC100%3/3
defined $params{"Code"} or defined $params{"Get"} and defined $params{"Put"}
defined $params{"Code"} defined $params{"Get"} defined $params{"Put"}
Truth table100%4/4
A or B and C
A= defined $params{"Code"}B= defined $params{"Get"}C= defined $params{"Put"}
ABCresult
1XX1
0111
00X0
0100
34 );
35 croak "Code element is not a subref"
36 8 ▶ unless (defined $params{Code} ? ref $params{Code} eq 'CODE' : 1);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $params{"Code"} ? ref $params{"Code"} eq "CODE" : 1 1 7 8
defined $params{'Code'} ? : 3 5 8
37 croak "Get or Put element is not a subref"
38 unless ((defined $params{Get} ? (ref $params{Get} eq 'CODE') : 1)
39 7 ▶ and (defined $params{Put} ? (ref $params{Put} eq 'CODE') : 1));
Branch: 3 branches
BranchTrueFalseTotal
unless defined $params{"Get"} ? ref $params{"Get"} eq "CODE" : 1 and defined $params{"Put"} ? ref $params{"Put"} eq "CODE" : 1 2 5 7
defined $params{'Get'} ? : 5 2 7
defined $params{'Put'} ? : 4 2 6
Condition100%3/3
defined $params{"Get"} ? ref $params{"Get"} eq "CODE" : 1 and defined $params{"Put"} ? ref $params{"Put"} eq "CODE" : 1
!ll&&!rl&&r
115
MC/DC100%2/2
defined $params{"Get"} ? ref $params{"Get"} eq "CODE" : 1 and defined $params{"Put"} ? ref $params{"Put"} eq "CODE" : 1
defined $params{"Get"} ? ref $params{"Get"} eq "CODE" : 1 defined $params{"Put"} ? ref $params{"Put"} eq "CODE" : 1
Truth table100%3/3
A and B
A= defined $params{"Get"} ? ref $params{"Get"} eq "CODE" : 1B= defined $params{"Put"} ? ref $params{"Put"} eq "CODE" : 1
ABresult
0X0
100
111
40  
41 5 ▶ my $get = $params{Code} || $params{Get};
Condition66%2/3
$params{'Code'} || $params{'Get'}
l!l&&r!l&&!r
230
MC/DC0%0/2
$params{'Code'} || $params{'Get'}
$params{'Code'} $params{'Get'}
Truth table66%2/3
A || B
A= $params{'Code'}B= $params{'Get'}
ABresult
1X1
011
000
42 5 ▶ my $put = $params{Code} || $params{Put};
Condition66%2/3
$params{'Code'} || $params{'Put'}
l!l&&r!l&&!r
230
MC/DC0%0/2
$params{'Code'} || $params{'Put'}
$params{'Code'} $params{'Put'}
Truth table66%2/3
A || B
A= $params{'Code'}B= $params{'Put'}
ABresult
1X1
011
000
43  
44 5 delete @params{qw(Code Get Put)};
45 5 ▶ carp("$type ignores unknown parameters: ", join(', ', sort keys %params))
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %params 0 5 5
46 if scalar keys %params;
47  
48  
49 5 my $self = bless [
50 [ ], # BUFFER
51 $get, # CODEGET
52 $put, # CODEPUT
53 ], $type;
54 }
55  
56 #------------------------------------------------------------------------------
57 # get() is inherited from POE::Filter.
58 # clone() is inherited from POE::Filter.
59  
60 #------------------------------------------------------------------------------
61  
62 5 ▶sub put {
Subroutine put: called CC=1 SCAR=0.0
Pod documented
63 5 my ($self, $data) = @_;
64 5 [ map { $self->[CODEPUT]->($_) } @$data ];
65 }
66  
67 #------------------------------------------------------------------------------
68 # 2001-07-26 RCC: The get_one variant of get() allows Wheel::Xyz to
69 # retrieve one filtered record at a time. This is necessary for
70 # filter changing and proper input flow control, even though it's kind
71 # of slow.
72  
73 9 ▶sub get_one_start {
Subroutine get_one_start: called CC=2 SCAR=7.1
Pod documented
74 9 my ($self, $stream) = @_;
75 9 ▶ push(@{$self->[BUFFER]}, @$stream) if defined $stream;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream 9 0 9
76 }
77  
78 24 ▶sub get_one {
Subroutine get_one: called CC=2 SCAR=6.9
Pod documented
79 24 my $self = shift;
80  
81 24 ▶ return [ ] unless @{$self->[BUFFER]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->[0];} 7 17 24
82 17 my $next_record = shift @{$self->[BUFFER]};
83 17 return [ map { $self->[CODEGET]->($_) } $next_record ];
84 }
85  
86 #------------------------------------------------------------------------------
87 # 2001-07-27 RCC: This filter now tracks state, so get_pending has
88 # become useful.
89  
90 2 ▶sub get_pending {
Subroutine get_pending: called CC=2 SCAR=6.9
Pod documented
91 2 my $self = shift;
92 2 ▶ return undef unless @{$self->[BUFFER]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->[0];} 1 1 2
93 1 [ @{$self->[BUFFER]} ];
94 }
95  
96 #------------------------------------------------------------------------------
97  
98 6 ▶sub modify {
Subroutine modify: called CC=7 SCAR=19.7
Pod documented
99 6 my ($self, %params) = @_;
100  
101 6 for (keys %params) {
102 6 ▶ (carp("Modify $_ element must be given a coderef") and next) unless (ref $params{$_} eq 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params{$_} eq "CODE" 3 3 6
Condition60%3/5
ref $params{$_} eq 'CODE' || carp("Modify $_ element must be given a coderef") && (next)
l!l
330
carp("Modify $_ element must be given a coderef") and next
!ll
03
MC/DC0%0/2
ref $params{$_} eq 'CODE' || carp("Modify $_ element must be given a coderef") && (next)
ref $params{$_} eq 'CODE' carp("Modify $_ element must be given a coderef")
Truth table66%2/3
A || B
A= ref $params{$_} eq 'CODE'B= carp("Modify $_ element must be given a coderef")
ABresult
1X1
011
000
103 3 ▶ if (lc eq 'code') {
Branch: 3 branches
BranchTrueFalseTotal
if (lc $_ eq 'code') { } 1 2 3
elsif (lc $_ eq 'put') { } 1 1 2
elsif (lc $_ eq 'get') { } 1 0 1
104 1 $self->[CODEGET] = $params{$_};
105 1 $self->[CODEPUT] = $params{$_};
106 }
107 elsif (lc eq 'put') {
108 1 $self->[CODEPUT] = $params{$_};
109 }
110 elsif (lc eq 'get') {
111 1 $self->[CODEGET] = $params{$_};
112 }
113 }
114 }
115  
116 4 1;
117  
118 __END__
« blib/lib/POE/Resource/Events.pm ↑ Summary blib/lib/POE/Filter/Grep.pm »