line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Sprintf::Named; |
2
|
|
|
|
|
|
|
$Text::Sprintf::Named::VERSION = '0.0404'; |
3
|
5
|
|
|
5
|
|
360876
|
use warnings; |
|
5
|
|
|
|
|
67
|
|
|
5
|
|
|
|
|
281
|
|
4
|
5
|
|
|
5
|
|
35
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
123
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
154
|
use 5.008; |
|
5
|
|
|
|
|
32
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
32
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
425
|
|
9
|
5
|
|
|
5
|
|
53
|
use warnings::register; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
881
|
|
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
2217
|
use parent 'Exporter'; |
|
5
|
|
|
|
|
1513
|
|
|
5
|
|
|
|
|
47
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
352
|
use vars qw(@EXPORT_OK); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
4041
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
@EXPORT_OK = (qw( named_sprintf )); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
20
|
|
|
20
|
1
|
6688
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
20
|
|
|
|
|
36
|
my $self = {}; |
23
|
20
|
|
|
|
|
41
|
bless $self, $class; |
24
|
|
|
|
|
|
|
|
25
|
20
|
|
|
|
|
61
|
$self->_init(@_); |
26
|
|
|
|
|
|
|
|
27
|
20
|
|
|
|
|
64
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _init |
31
|
|
|
|
|
|
|
{ |
32
|
20
|
|
|
20
|
|
42
|
my ($self, $args) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $fmt = $args->{fmt} or |
35
|
20
|
50
|
|
|
|
57
|
confess "The 'fmt format was not specified for Text::Sprintf::Named."; |
36
|
20
|
|
|
|
|
61
|
$self->_fmt($fmt); |
37
|
|
|
|
|
|
|
|
38
|
20
|
|
|
|
|
31
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _fmt |
42
|
|
|
|
|
|
|
{ |
43
|
43
|
|
|
43
|
|
61
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
43
|
100
|
|
|
|
104
|
if (@_) |
46
|
|
|
|
|
|
|
{ |
47
|
20
|
|
|
|
|
63
|
$self->{_fmt} = shift; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
43
|
|
|
|
|
83
|
return $self->{_fmt}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub format |
55
|
|
|
|
|
|
|
{ |
56
|
23
|
|
|
23
|
1
|
1157
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
23
|
|
100
|
|
|
71
|
my $args = shift || {}; |
59
|
|
|
|
|
|
|
|
60
|
23
|
100
|
100
|
|
|
38
|
if ( (scalar keys %{$args}) > 0 && not exists $args->{args} ){ |
|
23
|
|
|
|
|
124
|
|
61
|
2
|
|
|
|
|
63
|
warnings::warnif( $self, 'Format parameters were specified, but none of them were \'args\', this is probably a mistake.' ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
23
|
|
100
|
|
|
685
|
my $named_params = $args->{args} || {}; |
65
|
|
|
|
|
|
|
|
66
|
23
|
|
|
|
|
45
|
my $format = $self->_fmt; |
67
|
|
|
|
|
|
|
|
68
|
23
|
|
|
|
|
170
|
$format =~ s/%(%|\(([a-zA-Z_]\w*)\)([\+\-\.\d]*)([DEFGOUXbcdefgiopsux]))/ |
69
|
30
|
|
|
|
|
181
|
$self->_conversion({ |
70
|
|
|
|
|
|
|
format_args => $args, |
71
|
|
|
|
|
|
|
named_params => $named_params, |
72
|
|
|
|
|
|
|
conv => $1, |
73
|
|
|
|
|
|
|
name => $2, |
74
|
|
|
|
|
|
|
conv_prefix => $3, |
75
|
|
|
|
|
|
|
conv_letter => $4, |
76
|
|
|
|
|
|
|
}) |
77
|
|
|
|
|
|
|
/ge; |
78
|
|
|
|
|
|
|
|
79
|
23
|
|
|
|
|
263
|
return $format; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub calc_param |
84
|
|
|
|
|
|
|
{ |
85
|
17
|
|
|
17
|
1
|
32
|
my ($self, $args) = @_; |
86
|
17
|
100
|
|
|
|
50
|
if ( not exists $args->{named_params}->{$args->{name}} ){ |
87
|
4
|
|
|
|
|
225
|
warnings::warnif($self, "Token '$args->{name}' specified in the format '$self->{_fmt}' was not found." ); |
88
|
4
|
|
|
|
|
1821
|
return ''; |
89
|
|
|
|
|
|
|
} |
90
|
13
|
|
|
|
|
40
|
return $args->{named_params}->{$args->{name}}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _conversion |
94
|
|
|
|
|
|
|
{ |
95
|
30
|
|
|
30
|
|
64
|
my ($self, $args) = @_; |
96
|
|
|
|
|
|
|
|
97
|
30
|
100
|
|
|
|
67
|
if ($args->{conv} eq "%") |
98
|
|
|
|
|
|
|
{ |
99
|
12
|
|
|
|
|
42
|
return "%"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
return $self->_sprintf( |
104
|
18
|
|
|
|
|
57
|
("%" . $args->{conv_prefix} . $args->{conv_letter}), |
105
|
|
|
|
|
|
|
$self->calc_param($args), |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _sprintf |
111
|
|
|
|
|
|
|
{ |
112
|
18
|
|
|
18
|
|
62
|
my ($self, $format, @args) = @_; |
113
|
|
|
|
|
|
|
|
114
|
18
|
|
|
|
|
131
|
return sprintf($format, @args); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub named_sprintf |
119
|
|
|
|
|
|
|
{ |
120
|
2
|
|
|
2
|
1
|
871
|
my ($format, @args) = @_; |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
4
|
my $params; |
123
|
2
|
50
|
|
|
|
11
|
if (! @args) |
|
|
100
|
|
|
|
|
|
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
|
|
0
|
$params = {}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
elsif (ref($args[0]) eq "HASH") |
128
|
|
|
|
|
|
|
{ |
129
|
1
|
|
|
|
|
2
|
$params = shift(@args); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else |
132
|
|
|
|
|
|
|
{ |
133
|
1
|
|
|
|
|
4
|
$params = {@args}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return |
137
|
2
|
|
|
|
|
11
|
Text::Sprintf::Named->new({ fmt => $format}) |
138
|
|
|
|
|
|
|
->format({args => $params}); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; # End of Text::Sprintf::Named |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |