File Coverage

lib/POSIX/1003/Time.pm
Criterion Covered Total %
statement 29 34 85.2
branch 2 4 50.0
condition 2 6 33.3
subroutine 9 10 90.0
pod 1 1 100.0
total 43 55 78.1


line stmt bran cond sub pod time code
1             # Copyrights 2011-2015 by [Mark Overmeer].
2             # For other contributors see ChangeLog.
3             # See the manual pages for details on the licensing terms.
4             # Pod stripped from pm file by OODoc 2.01.
5 3     3   13500 use warnings;
  3         3  
  3         76  
6 3     3   9 use strict;
  3         3  
  3         79  
7              
8             package POSIX::1003::Time;
9 3     3   13 use vars '$VERSION';
  3         3  
  3         103  
10             $VERSION = '0.99_07';
11              
12 3     3   16 use base 'POSIX::1003::Module';
  3         4  
  3         345  
13              
14 3     3   501 use POSIX::1003::Locale qw(setlocale LC_TIME);
  3         5  
  3         15  
15 3     3   1261 use Encode qw(find_encoding is_utf8 decode);
  3         18533  
  3         389  
16              
17             our @IN_CORE = qw/gmtime localtime/;
18              
19             my @constants;
20             my @functions = qw/
21             asctime ctime strftime
22             clock difftime mktime
23             tzset tzname/;
24             push @functions, @IN_CORE;
25              
26             our %EXPORT_TAGS =
27             ( constants => \@constants
28             , functions => \@functions
29             , tables => [ '%time' ]
30             );
31              
32             my $time;
33             our %time;
34              
35             BEGIN {
36 3     3   17 $time = time_table;
37 3         8 push @constants, keys %$time;
38 3         19 tie %time, 'POSIX::1003::ReadOnlyTable', $time;
39             }
40              
41              
42             sub strftime($@)
43 1     1 1 394 { my $fmt = shift;
44              
45             #XXX See https://github.com/abeltje/lc_time for the correct implementation,
46             # using nl_langinfo(CODESET)
47              
48 1         10 my $lc = setlocale LC_TIME;
49 1 50 33     8 if($lc && $lc =~ m/\.([\w-]+)/ && (my $enc = find_encoding $1))
      33        
50             { # enforce the format string (may contain any text) to the same
51             # charset as the locale is using.
52 0         0 my $rawfmt = $enc->encode($fmt);
53 0         0 return $enc->decode(POSIX::strftime($rawfmt, @_));
54             }
55              
56 1 50       12 if(is_utf8($fmt))
57             { # no charset in locale, hence ascii inserts
58 0         0 my $out = POSIX::strftime(encode($fmt, 'utf8'), @_);
59 0         0 return decode $out, 'utf8';
60             }
61              
62             # don't know about the charset
63 1         34 POSIX::strftime($fmt, @_);
64             }
65              
66              
67             # Everything in POSIX.xs
68              
69              
70             sub _create_constant($)
71 1     1   2 { my ($class, $name) = @_;
72 1         2 my $val = $time->{$name};
73 1     0   7 sub () {$val};
  0            
74             }
75              
76             1;