File Coverage

blib/lib/Proc/ProcessTable/Match/Time.pm
Criterion Covered Total %
statement 8 56 14.2
branch 0 38 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod 2 2 100.0
total 13 104 12.5


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