lib/Pipeline/Segment/Tester.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 95.8% 46 / 48 CC 4 SCAR 4.5
CC
4
Cov
95%
init
2.1
pipe
2.0
test
2.0
CRAP 1.6
« blib/lib/Pipeline/Store/Simple.pm ↑ Summary blib/lib/Pipeline/Segment/Async/Handler.pm »
1 package Pipeline::Segment::Tester;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Pipeline;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Pipeline::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use base qw(Pipeline::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 our $VERSION = "3.12";
10  
11 5 ▶sub init {
Subroutine init: called CC=2 SCAR=7.4
Pod documented
12 5 my $self = shift;
13 5 ▶ if ($self->SUPER::init( @_ )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->SUPER::init(@_)) { } 5 0 5
14 5 $self->pipe( Pipeline->new() );
15 5 return 1;
16 } else {
17 0 return 0;
18 }
19 }
20  
21 10 ▶sub pipe {
Subroutine pipe: called CC=2 SCAR=6.9
Pod documented
22 10 my $self = shift;
23 10 my $pipe = shift;
24 10 ▶ if (defined($pipe)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pipe) { } 5 5 10
25 5 $self->{pipe} = $pipe;
26 5 return $self;
27 } else {
28 5 return $self->{pipe};
29 }
30 }
31  
32 1 ▶sub test {
Subroutine test: called CC=2 SCAR=6.9
Pod documented
33 1 my $self = shift;
34 1 my $seg = shift;
35  
36 1 $self->pipe->add_segment($seg);
37 1 $self->pipe->store->set($_) foreach @_;
38 1 return $self->pipe->dispatch();
39 # $self->pipe->debug( 1 );
40 # return (wantarray) ? ($self->pipe->dispatch) : [$self->pipe->dispatch];
41 # return $self->pipe->dispatch();
42 }
43  
44 2 1;
45  
46 =head1 NAME
47  
48 Pipeline::Segment::Tester - a test wrapper for a Pipeline::Segment
49  
50 =head1 SYNOPSIS
51  
52 use Pipeline::Segment::Tester;
53  
54 my $pst = Pipeline::Segment::Tester->new();
55 $pst->test( $segment, $objects, $in, $store );
56  
57 =head1 DESCRIPTION
58  
59 C<Pipeline::Segment::Tester> exists to make testing segments easier. Segments
60 will often rely on having multiple other objects in a pipeline store to be used
61 properly, which makes testing a bit icky, as the store and the pipeline need
62 to be set up to handle testing of a segment. Pipeline::Segment::Tester removes
63 this requirement by creating the pipeline and adding stuff to the store for you
64 before, and making your life easier.
65  
66 =head1 METHODS
67  
68 =over 4
69  
70 =item new()
71  
72 The C<new> method constructs a new Pipeline::Segment::Tester object and returns it.
73  
74 =item init()
75  
76 The C<init> method is called by the constructor and performs construction time initialization
77 on the object.
78  
79 =item test( Pipeline::Segment, [ ARRAY ] )
80  
81 The C<test> method takes a segment object as its first argument, which it will add to its
82 pipeline before dispatch. It also takes an infinite number of additional paramaters that
83 will be added to the store prior to dispatch of the pipeline.
84  
85 Returns the production of the pipeline.
86  
87 =item pipe( [ Pipeline ] )
88  
89 The C<pipe> method gets and sets the Pipeline object that Pipeline::Segment::Tester will use.
90  
91 =back
92  
93 =head1 AUTHOR
94  
95 James A. Duncan <jduncan@fotango.com>
96  
97 =cut
98  
99  
« blib/lib/Pipeline/Store/Simple.pm ↑ Summary blib/lib/Pipeline/Segment/Async/Handler.pm »