| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::Stream::Plugin::Grab; | 
| 2 | 37 |  |  | 37 |  | 188 | use strict; | 
|  | 37 |  |  |  |  | 74 |  | 
|  | 37 |  |  |  |  | 918 |  | 
| 3 | 37 |  |  | 37 |  | 187 | use warnings; | 
|  | 37 |  |  |  |  | 77 |  | 
|  | 37 |  |  |  |  | 952 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 37 |  |  | 37 |  | 193 | use Test::Stream::Sync; | 
|  | 37 |  |  |  |  | 70 |  | 
|  | 37 |  |  |  |  | 774 |  | 
| 6 | 37 |  |  | 37 |  | 197 | use Test::Stream::DebugInfo; | 
|  | 37 |  |  |  |  | 73 |  | 
|  | 37 |  |  |  |  | 806 |  | 
| 7 | 37 |  |  | 37 |  | 767 | use Test::Stream::Hub::Interceptor; | 
|  | 37 |  |  |  |  | 71 |  | 
|  | 37 |  |  |  |  | 897 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 37 |  |  | 37 |  | 198 | use Test::Stream::Exporter; | 
|  | 37 |  |  |  |  | 89 |  | 
|  | 37 |  |  |  |  | 259 |  | 
| 10 | 5 |  |  | 5 |  | 63 | default_export grab => sub { __PACKAGE__->new }; | 
| 11 | 37 |  |  | 37 |  | 215 | no Test::Stream::Exporter; | 
|  | 37 |  |  |  |  | 78 |  | 
|  | 37 |  |  |  |  | 1179 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | my $STACK = Test::Stream::Sync->stack; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | use Test::Stream::HashBase( | 
| 16 | 37 |  |  |  |  | 305 | accessors => [qw/hub finished _events term_size/], | 
| 17 | 37 |  |  | 37 |  | 214 | ); | 
|  | 37 |  |  |  |  | 74 |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | sub init { | 
| 20 | 5 |  |  | 5 | 0 | 10 | my $self = shift; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 5 |  |  |  |  | 8 | my $ipc; | 
| 23 | 5 | 50 |  |  |  | 20 | if ($INC{'Test/Stream/IPC.pm'}) { | 
| 24 | 5 |  |  |  |  | 28 | my ($driver) = Test::Stream::IPC->drivers; | 
| 25 | 5 |  |  |  |  | 32 | $ipc = $driver->new; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 5 |  |  |  |  | 58 | $self->{+HUB} = Test::Stream::Hub::Interceptor->new( | 
| 29 |  |  |  |  |  |  | ipc => $ipc, | 
| 30 |  |  |  |  |  |  | no_ending => 1, | 
| 31 |  |  |  |  |  |  | ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 5 |  |  |  |  | 10 | my @events; | 
| 34 | 5 |  |  | 6 |  | 48 | $self->{+HUB}->listen(sub { push @events => $_[1] }); | 
|  | 6 |  |  |  |  | 19 |  | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 5 |  |  |  |  | 14 | $self->{+_EVENTS} = \@events; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 5 |  |  |  |  | 27 | $STACK->top(); # Make sure there is a top hub before we begin. | 
| 39 | 5 |  |  |  |  | 22 | $STACK->push($self->{+HUB}); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 5 |  |  |  |  | 16 | $self->{+TERM_SIZE} = $ENV{TS_TERM_SIZE}; | 
| 42 | 5 |  |  |  |  | 42 | $ENV{TS_TERM_SIZE} = 80; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub flush { | 
| 46 | 5 |  |  | 5 | 1 | 10 | my $self = shift; | 
| 47 | 5 |  |  |  |  | 9 | my $out = [@{$self->{+_EVENTS}}]; | 
|  | 5 |  |  |  |  | 16 |  | 
| 48 | 5 |  |  |  |  | 8 | @{$self->{+_EVENTS}} = (); | 
|  | 5 |  |  |  |  | 13 |  | 
| 49 | 5 |  |  |  |  | 27 | return $out; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub events { | 
| 53 | 1 |  |  | 1 | 1 | 5 | my $self = shift; | 
| 54 |  |  |  |  |  |  | # Copy | 
| 55 | 1 |  |  |  |  | 2 | return [@{$self->{+_EVENTS}}]; | 
|  | 1 |  |  |  |  | 4 |  | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | sub finish { | 
| 59 | 5 |  |  | 5 | 1 | 14 | my ($self) = @_; # Do not shift; | 
| 60 | 5 |  |  |  |  | 12 | $_[0] = undef; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 5 | 50 |  |  |  | 19 | if (defined $self->{+TERM_SIZE}) { | 
| 63 | 0 |  |  |  |  | 0 | $ENV{TS_TERM_SIZE} = $self->{+TERM_SIZE}; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  | else { | 
| 66 | 5 |  |  |  |  | 24 | delete $ENV{TS_TERM_SIZE}; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 5 |  |  |  |  | 12 | my $hub = $self->{+HUB}; | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 5 |  |  |  |  | 14 | $self->{+FINISHED} = 1; | 
| 72 | 5 |  |  |  |  | 24 | $STACK->pop($hub); | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 5 |  |  |  |  | 58 | my $dbg = Test::Stream::DebugInfo->new( | 
| 75 |  |  |  |  |  |  | frame => [caller(0)], | 
| 76 |  |  |  |  |  |  | ); | 
| 77 | 5 | 0 | 33 |  |  | 27 | $hub->finalize($dbg, 1) | 
| 78 |  |  |  |  |  |  | if !$hub->no_ending | 
| 79 |  |  |  |  |  |  | && !$hub->state->ended; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 5 |  |  |  |  | 37 | return $self->flush; | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | sub DESTROY { | 
| 85 | 5 |  |  | 5 |  | 9 | my $self = shift; | 
| 86 | 5 | 50 |  |  |  | 38 | return if $self->{+FINISHED}; | 
| 87 | 0 |  |  |  |  |  | $STACK->pop($self->{+HUB}); | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | 1; | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | __END__ |