File Coverage

blib/lib/Proc/ProcessTable/Match/Cmndline.pm
Criterion Covered Total %
statement 8 37 21.6
branch 0 16 0.0
condition n/a
subroutine 3 5 60.0
pod 2 2 100.0
total 13 60 21.6


line stmt bran cond sub pod time code
1             package Proc::ProcessTable::Match::Cmndline;
2              
3 1     1   67519 use 5.006;
  1         14  
4 1     1   7 use strict;
  1         2  
  1         33  
5 1     1   5 use warnings;
  1         3  
  1         318  
6              
7             =head1 NAME
8              
9             Proc::ProcessTable::Match::Cmndline - Check if the cmndline of a process matches via regexp.
10              
11             =head1 VERSION
12              
13             Version 0.0.0
14              
15             =cut
16              
17             our $VERSION = '0.0.0';
18              
19              
20             =head1 SYNOPSIS
21              
22             use Proc::ProcessTable::Match::Cmndline;
23            
24             my %args=(
25             cmndlines=>[
26             'syslogd',
27             '^&',
28             ],
29             );
30            
31             my $checker=Proc::ProcessTable::Match::Cmndline->new( \%args );
32            
33             if ( $checker->match( $proc ) ){
34             print "It matches.\n";
35             }
36              
37             =head1 METHODS
38              
39             =head2 new
40              
41             This intiates the object.
42              
43             It takes a hash reference with one key. One key is required and
44             that is 'cmndlines', which is a array of cmndline values to match.
45              
46             The matching is done via regexp.
47              
48             Atleast one cmndline must be specified.
49              
50             If the new method fails, it dies.
51              
52             my %args=(
53             cmndlines=>[
54             'syslogd',
55             '^&',
56             ],
57             );
58            
59             my $checker=Proc::ProcessTable::Match::Cmndline->new( \%args );
60              
61             =cut
62              
63             sub new{
64 0     0 1   my %args;
65 0 0         if(defined($_[1])){
66 0           %args= %{$_[1]};
  0            
67             };
68              
69             # run some basic checks to make sure we have the minimum stuff required to work
70 0 0         if ( ! defined( $args{cmndlines} ) ){
71 0           die ('No cmndlines key specified in the argument hash');
72             }
73 0 0         if ( ref( \$args{cmndlines} ) eq 'ARRAY' ){
74 0           die ('The cmndlines key is not a array');
75             }
76 0 0         if ( ! defined $args{cmndlines}[0] ){
77 0           die ('Nothing defined in the cmndlines array');
78             }
79              
80             my $self = {
81             cmndlines=>$args{cmndlines},
82 0           };
83 0           bless $self;
84              
85 0           return $self;
86             }
87              
88             =head2 match
89              
90             Checks if a single Proc::ProcessTable::Process object matches the stack.
91              
92             One argument is taken and that is a Proc::ProcessTable::Process object.
93              
94             The returned value is a boolean.
95              
96             if ( $checker->match( $proc ) ){
97             print "The connection matches.\n";
98             }
99              
100             =cut
101              
102             sub match{
103 0     0 1   my $self=$_[0];
104 0           my $object=$_[1];
105              
106 0 0         if ( !defined( $object ) ){
107 0           return 0;
108             }
109              
110 0 0         if ( ref( $object ) ne 'Proc::ProcessTable::Process' ){
111 0           return 0;
112             }
113              
114 0           my $proc_cmndline;
115 0           eval{
116 0           $proc_cmndline=$object->cmndline;
117             };
118              
119             # don't bother proceeding, the object won't match ever
120             # as it does not have a cmndline
121 0 0         if ( ! defined( $proc_cmndline ) ){
122 0           return 0;
123             }
124              
125 0           foreach my $cmndline ( @{ $self->{cmndlines} } ){
  0            
126 0 0         if ( $proc_cmndline =~ /$cmndline/ ){
127 0           return 1;
128             }
129             }
130              
131 0           return 0;
132             }
133              
134             =head1 AUTHOR
135              
136             Zane C. Bowers-Hadley, C<< >>
137              
138             =head1 BUGS
139              
140             Please report any bugs or feature requests to C, or through
141             the web interface at L. I will be notified, and then you'll
142             automatically be notified of progress on your bug as I make changes.
143              
144              
145              
146              
147             =head1 SUPPORT
148              
149             You can find documentation for this module with the perldoc command.
150              
151             perldoc Proc::ProcessTable::Match
152              
153              
154             You can also look for information at:
155              
156             =over 4
157              
158             =item * RT: CPAN's request tracker (report bugs here)
159              
160             L
161              
162             =item * AnnoCPAN: Annotated CPAN documentation
163              
164             L
165              
166             =item * CPAN Ratings
167              
168             L
169              
170             =item * Search CPAN
171              
172             L
173              
174             =back
175              
176              
177             =head1 ACKNOWLEDGEMENTS
178              
179              
180             =head1 LICENSE AND COPYRIGHT
181              
182             Copyright 2019 Zane C. Bowers-Hadley.
183              
184             This program is free software; you can redistribute it and/or modify it
185             under the terms of the the Artistic License (2.0). You may obtain a
186             copy of the full license at:
187              
188             L
189              
190             Any use, modification, and distribution of the Standard or Modified
191             Versions is governed by this Artistic License. By using, modifying or
192             distributing the Package, you accept this license. Do not use, modify,
193             or distribute the Package, if you do not accept this license.
194              
195             If your Modified Version has been derived from a Modified Version made
196             by someone other than you, you are nevertheless required to ensure that
197             your Modified Version complies with the requirements of this license.
198              
199             This license does not grant you the right to use any trademark, service
200             mark, tradename, or logo of the Copyright Holder.
201              
202             This license includes the non-exclusive, worldwide, free-of-charge
203             patent license to make, have made, use, offer to sell, sell, import and
204             otherwise transfer the Package with respect to any patent claims
205             licensable by the Copyright Holder that are necessarily infringed by the
206             Package. If you institute patent litigation (including a cross-claim or
207             counterclaim) against any party alleging that the Package constitutes
208             direct or contributory patent infringement, then this Artistic License
209             to you shall terminate on the date that such litigation is filed.
210              
211             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
212             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
213             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
214             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
215             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
216             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
217             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
218             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
219              
220              
221             =cut
222              
223             1; # End of Proc::ProcessTable::Match