File Coverage

blib/lib/Tail/Tool/Plugin/Match.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 1 1 100.0
total 36 38 94.7


line stmt bran cond sub pod time code
1             package Tail::Tool::Plugin::Match;
2              
3             # Created on: 2010-10-06 14:16:02
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 2     2   2335 use Moose;
  2         473957  
  2         14  
10 2     2   13681 use warnings;
  2         6  
  2         72  
11 2     2   686 use version;
  2         2087  
  2         16  
12 2     2   136 use Carp;
  2         4  
  2         162  
13 2     2   552 use English qw/ -no_match_vars /;
  2         1843  
  2         20  
14              
15             extends 'Tail::Tool::PreProcess';
16             with 'Tail::Tool::RegexList';
17              
18             our $VERSION = version->new('0.4.8');
19              
20             sub process {
21 2     2 1 1158 my ($self, $line) = @_;
22 2         5 my $matches;
23              
24 2         4 for my $match ( @{ $self->regex } ) {
  2         69  
25 2         53 $matches += $match->enabled;
26 2         52 my $reg = $match->regex;
27 2 100 66     47 if ( $match->enabled && $line =~ /$reg/ ) {
28             # return the line if it matches
29 1         6 return ($line);
30             }
31             }
32              
33             # return empty array if there were enabled matches else return the line
34 1 50       8 return $matches ? () : ($line);
35             }
36              
37             1;
38              
39             __END__
40              
41             =head1 NAME
42              
43             Tail::Tool::Plugin::Match - Checks that each line passed matches a regex
44              
45             =head1 VERSION
46              
47             This documentation refers to Tail::Tool::Plugin::Match version 0.4.8.
48              
49              
50             =head1 SYNOPSIS
51              
52             use Tail::Tool::Plugin::Match;
53              
54             # Brief but working code example(s) here showing the most common usage(s)
55             # This section will be as far as many users bother reading, so make it as
56             # educational and exemplary as possible.
57              
58              
59             =head1 DESCRIPTION
60              
61             =head1 SUBROUTINES/METHODS
62              
63             =head2 C<new (%params)>
64              
65             Param: regex - ArrayRef - List of regular expressions that lines must match
66              
67             =head2 C<process ($line)>
68              
69             Description: Check the the C<$line> passed matches at least one enabled regular
70             expression. The line will be returned if it matches or if there are no enabled
71             regular expressions, otherwise no line is returned.
72              
73             =head1 DIAGNOSTICS
74              
75             A list of every error and warning message that the module can generate (even
76             the ones that will "never happen"), with a full explanation of each problem,
77             one or more likely causes, and any suggested remedies.
78              
79             =head1 CONFIGURATION AND ENVIRONMENT
80              
81             A full explanation of any configuration system(s) used by the module, including
82             the names and locations of any configuration files, and the meaning of any
83             environment variables or properties that can be set. These descriptions must
84             also include details of any configuration language used.
85              
86             =head1 DEPENDENCIES
87              
88             A list of all of the other modules that this module relies upon, including any
89             restrictions on versions, and an indication of whether these required modules
90             are part of the standard Perl distribution, part of the module's distribution,
91             or must be installed separately.
92              
93             =head1 INCOMPATIBILITIES
94              
95             A list of any modules that this module cannot be used in conjunction with.
96             This may be due to name conflicts in the interface, or competition for system
97             or program resources, or due to internal limitations of Perl (for example, many
98             modules that use source code filters are mutually incompatible).
99              
100             =head1 BUGS AND LIMITATIONS
101              
102             A list of known problems with the module, together with some indication of
103             whether they are likely to be fixed in an upcoming release.
104              
105             Also, a list of restrictions on the features the module does provide: data types
106             that cannot be handled, performance issues and the circumstances in which they
107             may arise, practical limitations on the size of data sets, special cases that
108             are not (yet) handled, etc.
109              
110             The initial template usually just has:
111              
112             There are no known bugs in this module.
113              
114             Please report problems to Ivan Wills (ivan.wills@gamil.com).
115              
116             Patches are welcome.
117              
118             =head1 AUTHOR
119              
120             Ivan Wills - (ivan.wills@gamil.com)
121             <Author name(s)> (<contact address>)
122              
123             =head1 LICENSE AND COPYRIGHT
124              
125             Copyright (c) 2010 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW, Australia, 2077).
126             All rights reserved.
127              
128             This module is free software; you can redistribute it and/or modify it under
129             the same terms as Perl itself. See L<perlartistic>. This program is
130             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
131             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
132             PARTICULAR PURPOSE.
133              
134             =cut