File Coverage

blib/lib/IO/Capture/Extended.pm
Criterion Covered Total %
statement 30 30 100.0
branch 10 10 100.0
condition n/a
subroutine 8 8 100.0
pod 0 5 0.0
total 48 53 90.5


line stmt bran cond sub pod time code
1             package IO::Capture::Extended;
2 2     2   13 use strict;
  2         4  
  2         128  
3 2     2   19 use warnings;
  2         5  
  2         979  
4             our $VERSION = 0.12; # as of 05-17-2014
5             require Exporter;
6             our @ISA = qw(Exporter);
7             our @EXPORT_OK = qw(
8             grep_print_statements
9             statements
10             matches
11             matches_ref
12             all_screen_lines
13             );
14             our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
15              
16              
17             sub grep_print_statements {
18 10     10 0 2799 my $self = shift;
19 10         12 my $string = shift;
20 10         12 my @found_statements;
21            
22 10         11 for my $statement (@{$self->{'IO::Capture::messages'}}) {
  10         22  
23 40 100       151 push @found_statements, $statement if $statement =~ /$string/;
24             }
25 10 100       48 return wantarray ? @found_statements : scalar(@found_statements);
26             }
27              
28             sub statements {
29 12     12 0 5468 my $self = shift;
30 12         39 return scalar(@{$self->{'IO::Capture::messages'}});
  12         46  
31             };
32              
33             sub matches {
34 8     8 0 3208 my @matches = _matches_engine(@_);
35 6 100       42 return wantarray ? @matches : scalar(@matches);
36             }
37              
38             sub matches_ref {
39 2     2 0 770 my @matches = _matches_engine(@_);
40 2         8 return \@matches;
41             }
42              
43             sub _matches_engine {
44 10     10   15 my ($self, $regex) = @_;
45 10 100       44 die "Not enough arguments: $!"
46             if (! defined $regex);
47 8         12 my $str = join('', @{$self->{'IO::Capture::messages'}});
  8         49  
48 8         145 my @matches = $str =~ m/$regex/g;
49             }
50              
51             sub all_screen_lines {
52 26     26 0 6099 my $self = shift;
53 26         29 my @screen_lines;
54 26         37 @screen_lines = split(/\n/, join('', @{$self->{'IO::Capture::messages'}}));
  26         134  
55 26 100       119 return wantarray ? @screen_lines : scalar(@screen_lines);
56             }
57              
58             ########## DOCUMENTATION ##########
59              
60             =head1 NAME
61              
62             IO::Capture::Extended - Extend functionality of IO::Capture
63              
64             =head1 SYNOPSIS
65              
66             All documentation is contained in IO::Capture::Extended::Overview.
67              
68             perldoc IO::Capture::Extended::Overview
69              
70             =cut
71              
72             1;
73