File Coverage

blib/lib/App/Timer.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 14 14 100.0


line stmt bran cond sub pod time code
1             package App::Timer;
2              
3             $App::Timer::VERSION = '0.02';
4             $App::Timer::AUTHORITY = 'cpan:MANWAR';
5              
6 1     1   56852 use strict;
  1         2  
  1         23  
7 1     1   4 use warnings;
  1         1  
  1         120  
8              
9             =head1 NAME
10              
11             App::Timer - Timer for your application.
12              
13             =head1 VERSION
14              
15             Version 0.02
16              
17             =head1 DESCRIPTION
18              
19             Every time, I create a command line tool in B, I would just add
20             the following lines at the end of the script.
21              
22             END {
23             my $time = time - $^T;
24             my $mm = $time / 60;
25             my $ss = $time % 60;
26             my $hh = $mm / 60;
27              
28             printf("The program ran for %02d:%02d:%02d.\n", $hh, $mm%60, $ss);
29             }
30              
31             Having done it more than once, I decided to come up with something as
32             smooth as possible. This is my pure Perl solution.
33              
34             I found somewhat similar work done in L. The only issue
35             is that it has dependency on a non-core module L.
36              
37             =head1 SYNOPSIS
38              
39             To get the timer enable for your command line tool, just add the line
40             below at the top of the script and you are good to go.
41              
42             use App::Timer;
43              
44             Or if you don't want to pollute your script then you can do this too.
45              
46             $ perl -MApp::Timer your-script.pl
47              
48             =cut
49              
50             sub import {
51             END {
52 1     1   565 my $time = time - $^T;
53 1         3 my $mm = $time / 60;
54 1         3 my $ss = $time % 60;
55 1         2 my $hh = $mm / 60;
56              
57 1         43 printf("The program ran for %02d:%02d:%02d.\n", $hh, $mm%60, $ss);
58             }
59             }
60              
61             =head1 AUTHOR
62              
63             Mohammad S Anwar, C<< >>
64              
65             =head1 REPOSITORY
66              
67             L
68              
69             =head1 SEE ALSO
70              
71             L
72              
73             =head1 BUGS
74              
75             Please report any bugs or feature requests to C,
76             or through the web interface at L.
77             I will be notified and then you'll automatically be notified of progress on your
78             bug as I make changes.
79              
80             =head1 SUPPORT
81              
82             You can find documentation for this module with the perldoc command.
83              
84             perldoc App::Timer
85              
86             You can also look for information at:
87              
88             =over 4
89              
90             =item * CPAN Ratings
91              
92             L
93              
94             =item * Search MetaCPAN
95              
96             L
97              
98             =back
99              
100             =head1 LICENSE AND COPYRIGHT
101              
102             Copyright (C) 2022 Mohammad S Anwar.
103              
104             This program is free software; you can redistribute it and / or modify it under
105             the terms of the the Artistic License (2.0). You may obtain a copy of the full
106             license at:
107              
108             L
109              
110             Any use, modification, and distribution of the Standard or Modified Versions is
111             governed by this Artistic License.By using, modifying or distributing the Package,
112             you accept this license. Do not use, modify, or distribute the Package, if you do
113             not accept this license.
114              
115             If your Modified Version has been derived from a Modified Version made by someone
116             other than you,you are nevertheless required to ensure that your Modified Version
117             complies with the requirements of this license.
118              
119             This license does not grant you the right to use any trademark, service mark,
120             tradename, or logo of the Copyright Holder.
121              
122             This license includes the non-exclusive, worldwide, free-of-charge patent license
123             to make, have made, use, offer to sell, sell, import and otherwise transfer the
124             Package with respect to any patent claims licensable by the Copyright Holder that
125             are necessarily infringed by the Package. If you institute patent litigation
126             (including a cross-claim or counterclaim) against any party alleging that the
127             Package constitutes direct or contributory patent infringement,then this Artistic
128             License to you shall terminate on the date that such litigation is filed.
129              
130             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
131             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
132             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
133             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
134             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
135             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
136             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
137              
138             =cut
139              
140             1; # End of App::Timer