line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Sprintf::Named; |
2
|
|
|
|
|
|
|
$Text::Sprintf::Named::VERSION = '0.0403'; |
3
|
5
|
|
|
5
|
|
375760
|
use warnings; |
|
5
|
|
|
|
|
53
|
|
|
5
|
|
|
|
|
175
|
|
4
|
5
|
|
|
5
|
|
29
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
98
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
95
|
use 5.008; |
|
5
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
27
|
use Carp; |
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
384
|
|
9
|
5
|
|
|
5
|
|
40
|
use warnings::register; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
736
|
|
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
2339
|
use parent 'Exporter'; |
|
5
|
|
|
|
|
1503
|
|
|
5
|
|
|
|
|
29
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
341
|
use vars qw(@EXPORT_OK); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
3643
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
@EXPORT_OK = (qw( named_sprintf )); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
20
|
|
|
20
|
1
|
6648
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
20
|
|
|
|
|
44
|
my $self = {}; |
23
|
20
|
|
|
|
|
40
|
bless $self, $class; |
24
|
|
|
|
|
|
|
|
25
|
20
|
|
|
|
|
66
|
$self->_init(@_); |
26
|
|
|
|
|
|
|
|
27
|
20
|
|
|
|
|
60
|
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
|
|
|
|
56
|
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
|
|
|
|
101
|
if (@_) |
46
|
|
|
|
|
|
|
{ |
47
|
20
|
|
|
|
|
61
|
$self->{_fmt} = shift; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
43
|
|
|
|
|
84
|
return $self->{_fmt}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub format |
55
|
|
|
|
|
|
|
{ |
56
|
23
|
|
|
23
|
1
|
1106
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
23
|
|
100
|
|
|
73
|
my $args = shift || {}; |
59
|
|
|
|
|
|
|
|
60
|
23
|
100
|
100
|
|
|
33
|
if ( (scalar keys %{$args}) > 0 && not exists $args->{args} ){ |
|
23
|
|
|
|
|
129
|
|
61
|
2
|
|
|
|
|
62
|
warnings::warnif( $self, 'Format parameters were specified, but none of them were \'args\', this is probably a mistake.' ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
23
|
|
100
|
|
|
680
|
my $named_params = $args->{args} || {}; |
65
|
|
|
|
|
|
|
|
66
|
23
|
|
|
|
|
48
|
my $format = $self->_fmt; |
67
|
|
|
|
|
|
|
|
68
|
23
|
|
|
|
|
164
|
$format =~ s/%(%|\(([a-zA-Z_]\w*)\)([\+\-\.\d]*)([DEFGOUXbcdefgiopsux]))/ |
69
|
30
|
|
|
|
|
185
|
$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
|
|
|
|
|
284
|
return $format; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub calc_param |
84
|
|
|
|
|
|
|
{ |
85
|
17
|
|
|
17
|
1
|
37
|
my ($self, $args) = @_; |
86
|
17
|
100
|
|
|
|
47
|
if ( not exists $args->{named_params}->{$args->{name}} ){ |
87
|
4
|
|
|
|
|
217
|
warnings::warnif($self, "Token '$args->{name}' specified in the format '$self->{_fmt}' was not found." ); |
88
|
4
|
|
|
|
|
1731
|
return ''; |
89
|
|
|
|
|
|
|
} |
90
|
13
|
|
|
|
|
41
|
return $args->{named_params}->{$args->{name}}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _conversion |
94
|
|
|
|
|
|
|
{ |
95
|
30
|
|
|
30
|
|
64
|
my ($self, $args) = @_; |
96
|
|
|
|
|
|
|
|
97
|
30
|
100
|
|
|
|
68
|
if ($args->{conv} eq "%") |
98
|
|
|
|
|
|
|
{ |
99
|
12
|
|
|
|
|
42
|
return "%"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
return $self->_sprintf( |
104
|
18
|
|
|
|
|
54
|
("%" . $args->{conv_prefix} . $args->{conv_letter}), |
105
|
|
|
|
|
|
|
$self->calc_param($args), |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _sprintf |
111
|
|
|
|
|
|
|
{ |
112
|
18
|
|
|
18
|
|
58
|
my ($self, $format, @args) = @_; |
113
|
|
|
|
|
|
|
|
114
|
18
|
|
|
|
|
148
|
return sprintf($format, @args); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub named_sprintf |
119
|
|
|
|
|
|
|
{ |
120
|
2
|
|
|
2
|
1
|
836
|
my ($format, @args) = @_; |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
3
|
my $params; |
123
|
2
|
50
|
|
|
|
10
|
if (! @args) |
|
|
100
|
|
|
|
|
|
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
|
|
0
|
$params = {}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
elsif (ref($args[0]) eq "HASH") |
128
|
|
|
|
|
|
|
{ |
129
|
1
|
|
|
|
|
3
|
$params = shift(@args); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else |
132
|
|
|
|
|
|
|
{ |
133
|
1
|
|
|
|
|
5
|
$params = {@args}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return |
137
|
2
|
|
|
|
|
12
|
Text::Sprintf::Named->new({ fmt => $format}) |
138
|
|
|
|
|
|
|
->format({args => $params}); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; # End of Text::Sprintf::Named |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |