cXML/Utils.pm

filter: Statementstmt 90.9% 20 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 90.9% 30 / 33 CC 1 SCAR 1.2
CC
1
Cov
91%
cxml_timestamp
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« cXML/Description.pm ↑ Summary cXML/Carrier.pm »
1 =encoding utf-8
2  
3 =head1 NAME
4  
5 Business::cXML::Utils - Utilities for the cXML suite
6  
7 =head1 SYNOPSIS
8  
9 use Business::cXML::Utils;
10  
11 =head1 DESCRIPTION
12  
13 Various utilities not specific to any one cXML module.
14  
15 =cut
16  
17 10 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 package Business::cXML::Utils;
21 10 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 10 our @EXPORT_OK = qw(to_numeric current_datetime cxml_timestamp);
24  
25 10 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 10 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 =head1 FUNCTIONS
29  
30 =over
31  
32 =item C<B<to_numeric>( I<$string> )>
33  
34 Returns purely numbers from I<C<$string>>. (i.e. C<1 234,567.88> becomes
35 C<123456788>)
36  
37 =cut
38  
39 18 ▶sub to_numeric {
Subroutine to_numeric: called CC=1 SCAR=0.0
Pod documented
40 18 my ($str) = @_;
41 18 $str =~ tr/0123456789//dc; # Strip any character we don't know/need
42 18 return $str;
43 }
44  
45 =item C<B<current_datetime>()>
46  
47 Returns a L<DateTime> object for current time in local timezone.
48  
49 =cut
50  
51 10 ▶sub current_datetime {
Subroutine current_datetime: called CC=1 SCAR=0.0
Pod documented
52 10 return DateTime->now(time_zone => DateTime::TimeZone->new( name => 'local' ));
53 }
54  
55 =item C<B<cxml_timestamp>( I<$datetime> )>
56  
57 Returns the ISO 8601 timestamp from I<C<$datetime>> (such as returned by
58 L</now()>). Example: C<2017-01-01T01:01:01-0800>
59  
60 =cut
61  
62 0 ▶sub cxml_timestamp {
Subroutine cxml_timestamp: not called CC=1 SCAR=6.9
Pod documented
63 0 my ($dt) = @_;
64 0 return $dt->strftime('%FT%T%z');
65 }
66  
67 =back
68  
69 =head1 AUTHOR
70  
71 Stéphane Lavergne L<https://github.com/vphantom>
72  
73 =head1 ACKNOWLEDGEMENTS
74  
75 Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
76  
77 =head1 COPYRIGHT & LICENSE
78  
79 Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
80  
81 Permission is hereby granted, free of charge, to any person obtaining a copy
82 of this software and associated documentation files (the "Software"), to deal
83 in the Software without restriction, including without limitation the rights
84 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
85 copies of the Software, and to permit persons to whom the Software is
86 furnished to do so, subject to the following conditions:
87  
88 The above copyright notice and this permission notice shall be included in all
89 copies or substantial portions of the Software.
90  
91 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
92 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
93 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
94 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
96 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
97 SOFTWARE.
98  
99 =cut
100  
101 10 1;
« cXML/Description.pm ↑ Summary cXML/Carrier.pm »