File Coverage

blib/lib/Business/cXML/Utils.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 31 31 100.0


line stmt bran cond sub pod time code
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     10   136 use 5.014;
  10         50  
18 10     10   44 use strict;
  10         16  
  10         304  
19              
20             use base 'Exporter';
21 10     10   71  
  10         25  
  10         781  
22             our @EXPORT_OK = qw(to_numeric current_datetime cxml_timestamp);
23              
24             use DateTime;
25 10     10   7526 use Sys::Hostname;
  10         4461892  
  10         427  
26 10     10   4643  
  10         9612  
  10         1533  
27             =head1 FUNCTIONS
28              
29             =over
30              
31             =item C<B<to_numeric>( I<$string> )>
32              
33             Returns purely numbers from I<C<$string>>. (i.e. C<1 234,567.88> becomes
34             C<123456788>)
35              
36             =cut
37              
38             my ($str) = @_;
39             $str =~ tr/0123456789//dc; # Strip any character we don't know/need
40 76     76 1 147 return $str;
41 76         201 }
42 76         231  
43             =item C<B<current_datetime>()>
44              
45             Returns a L<DateTime> object for current time in local timezone.
46              
47             =cut
48              
49             return DateTime->now(time_zone => DateTime::TimeZone->new( name => 'local' ));
50             }
51              
52 52     52 1 348 =item C<B<cxml_timestamp>( I<$datetime> )>
53              
54             Returns the ISO 8601 timestamp from I<C<$datetime>> (such as returned by
55             L</now()>). Example: C<2017-01-01T01:01:01-0800>
56              
57             =cut
58              
59             my ($dt) = @_;
60             return $dt->strftime('%FT%T%z');
61             }
62              
63 52     52 1 133 =back
64 52         196  
65             =head1 AUTHOR
66              
67             Stéphane Lavergne L<https://github.com/vphantom>
68              
69             =head1 ACKNOWLEDGEMENTS
70              
71             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
72              
73             =head1 COPYRIGHT & LICENSE
74              
75             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
76              
77             Permission is hereby granted, free of charge, to any person obtaining a copy
78             of this software and associated documentation files (the "Software"), to deal
79             in the Software without restriction, including without limitation the rights
80             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
81             copies of the Software, and to permit persons to whom the Software is
82             furnished to do so, subject to the following conditions:
83              
84             The above copyright notice and this permission notice shall be included in all
85             copies or substantial portions of the Software.
86              
87             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
89             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
90             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
91             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
92             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
93             SOFTWARE.
94              
95             =cut
96              
97             1;