File Coverage

lib/Pipeline/Segment/Tester.pm
Criterion Covered Total %
statement 30 31 96.7
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 44 46 95.6


line stmt bran cond sub pod time code
1             package Pipeline::Segment::Tester;
2              
3 2     2   20924 use strict;
  2         4  
  2         66  
4 2     2   10 use warnings::register;
  2         3  
  2         332  
5              
6 2     2   359 use Pipeline;
  2         4  
  2         45  
7 2     2   11 use Pipeline::Base;
  2         5  
  2         2451  
8 2     2   15 use base qw(Pipeline::Base);
  2         3  
  2         597  
9             our $VERSION = "3.12";
10              
11             sub init {
12 5     5 1 7 my $self = shift;
13 5 50       22 if ($self->SUPER::init( @_ )) {
14 5         24 $self->pipe( Pipeline->new() );
15 5         15 return 1;
16             } else {
17 0         0 return 0;
18             }
19             }
20              
21             sub pipe {
22 10     10 1 18 my $self = shift;
23 10         10 my $pipe = shift;
24 10 100       21 if (defined($pipe)) {
25 5         25 $self->{pipe} = $pipe;
26 5         10 return $self;
27             } else {
28 5         17 return $self->{pipe};
29             }
30             }
31              
32             sub test {
33 1     1 1 6 my $self = shift;
34 1         2 my $seg = shift;
35              
36 1         2 $self->pipe->add_segment($seg);
37 1         3 $self->pipe->store->set($_) foreach @_;
38 1         4 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             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 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 method constructs a new Pipeline::Segment::Tester object and returns it.
73              
74             =item init()
75              
76             The C 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 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 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
96              
97             =cut
98              
99