File Coverage

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