File Coverage

blib/lib/Mail/SpamAssassin/Util/ScopedTimer.pm
Criterion Covered Total %
statement 9 16 56.2
branch 0 2 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod 0 1 0.0
total 12 27 44.4


line stmt bran cond sub pod time code
1             # Helper code to debug dependencies and their versions.
2              
3             # <@LICENSE>
4             # Licensed to the Apache Software Foundation (ASF) under one or more
5             # contributor license agreements. See the NOTICE file distributed with
6             # this work for additional information regarding copyright ownership.
7             # The ASF licenses this file to you under the Apache License, Version 2.0
8             # (the "License"); you may not use this file except in compliance with
9             # the License. You may obtain a copy of the License at:
10             #
11             # http://www.apache.org/licenses/LICENSE-2.0
12             #
13             # Unless required by applicable law or agreed to in writing, software
14             # distributed under the License is distributed on an "AS IS" BASIS,
15             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16             # See the License for the specific language governing permissions and
17             # limitations under the License.
18             # </@LICENSE>
19              
20             package Mail::SpamAssassin::Util::ScopedTimer;
21              
22 40     40   297 use strict;
  40         108  
  40         1299  
23 40     40   259 use warnings;
  40         120  
  40         1354  
24             # use bytes;
25 40     40   254 use re 'taint';
  40         151  
  40         6578  
26              
27             our @ISA = qw();
28              
29             sub new {
30 0     0 0   my $class = shift;
31 0           my $self = {
32             main => shift,
33             timer => shift,
34             };
35 0           $self->{main}->timer_start($self->{timer});
36 0           return bless ($self, $class);
37             }
38              
39             # OO hack: when the object goes out of scope, the timer ends. neat!
40             sub DESTROY {
41 0     0     my $self = shift;
42             # best practices: prevent potential calls to eval and to system routines
43             # in code of a DESTROY method from clobbering global variables $@ and $!
44 0           local($@,$!); # keep outer error handling unaffected by DESTROY
45 0 0 0       $self->{main} && $self->{timer} && $self->{main}->timer_end($self->{timer});
46             }
47              
48             1;