line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Sprintf::Named; |
2
|
|
|
|
|
|
|
$Text::Sprintf::Named::VERSION = '0.0405'; |
3
|
5
|
|
|
5
|
|
319853
|
use warnings; |
|
5
|
|
|
|
|
48
|
|
|
5
|
|
|
|
|
149
|
|
4
|
5
|
|
|
5
|
|
23
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
104
|
use 5.008; |
|
5
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
23
|
use Carp; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
280
|
|
9
|
5
|
|
|
5
|
|
39
|
use warnings::register; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
671
|
|
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
1526
|
use parent 'Exporter'; |
|
5
|
|
|
|
|
1072
|
|
|
5
|
|
|
|
|
36
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
257
|
use vars qw(@EXPORT_OK); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
2940
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
@EXPORT_OK = (qw( named_sprintf )); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
20
|
|
|
20
|
1
|
5533
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
20
|
|
|
|
|
35
|
my $self = {}; |
23
|
20
|
|
|
|
|
31
|
bless $self, $class; |
24
|
|
|
|
|
|
|
|
25
|
20
|
|
|
|
|
54
|
$self->_init(@_); |
26
|
|
|
|
|
|
|
|
27
|
20
|
|
|
|
|
55
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _init |
31
|
|
|
|
|
|
|
{ |
32
|
20
|
|
|
20
|
|
32
|
my ($self, $args) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $fmt = $args->{fmt} or |
35
|
20
|
50
|
|
|
|
50
|
confess "The 'fmt format was not specified for Text::Sprintf::Named."; |
36
|
20
|
|
|
|
|
51
|
$self->_fmt($fmt); |
37
|
|
|
|
|
|
|
|
38
|
20
|
|
|
|
|
26
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _fmt |
42
|
|
|
|
|
|
|
{ |
43
|
43
|
|
|
43
|
|
52
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
43
|
100
|
|
|
|
115
|
if (@_) |
46
|
|
|
|
|
|
|
{ |
47
|
20
|
|
|
|
|
52
|
$self->{_fmt} = shift; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
43
|
|
|
|
|
64
|
return $self->{_fmt}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub format |
55
|
|
|
|
|
|
|
{ |
56
|
23
|
|
|
23
|
1
|
919
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
23
|
|
100
|
|
|
57
|
my $args = shift || {}; |
59
|
|
|
|
|
|
|
|
60
|
23
|
100
|
100
|
|
|
29
|
if ( (scalar keys %{$args}) > 0 && not exists $args->{args} ){ |
|
23
|
|
|
|
|
110
|
|
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
|
|
|
560
|
my $named_params = $args->{args} || {}; |
65
|
|
|
|
|
|
|
|
66
|
23
|
|
|
|
|
39
|
my $format = $self->_fmt; |
67
|
|
|
|
|
|
|
|
68
|
23
|
|
|
|
|
140
|
$format =~ s/%(%|\(([a-zA-Z_]\w*)\)([\+\-\.\d]*)([DEFGOUXbcdefgiopsux]))/ |
69
|
30
|
|
|
|
|
167
|
$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
|
|
|
|
|
220
|
return $format; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub calc_param |
84
|
|
|
|
|
|
|
{ |
85
|
17
|
|
|
17
|
1
|
23
|
my ($self, $args) = @_; |
86
|
17
|
100
|
|
|
|
43
|
if ( not exists $args->{named_params}->{$args->{name}} ){ |
87
|
4
|
|
|
|
|
191
|
warnings::warnif($self, "Token '$args->{name}' specified in the format '$self->{_fmt}' was not found." ); |
88
|
4
|
|
|
|
|
1441
|
return ''; |
89
|
|
|
|
|
|
|
} |
90
|
13
|
|
|
|
|
35
|
return $args->{named_params}->{$args->{name}}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _conversion |
94
|
|
|
|
|
|
|
{ |
95
|
30
|
|
|
30
|
|
58
|
my ($self, $args) = @_; |
96
|
|
|
|
|
|
|
|
97
|
30
|
100
|
|
|
|
61
|
if ($args->{conv} eq "%") |
98
|
|
|
|
|
|
|
{ |
99
|
12
|
|
|
|
|
37
|
return "%"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
return $self->_sprintf( |
104
|
18
|
|
|
|
|
49
|
("%" . $args->{conv_prefix} . $args->{conv_letter}), |
105
|
|
|
|
|
|
|
$self->calc_param($args), |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _sprintf |
111
|
|
|
|
|
|
|
{ |
112
|
18
|
|
|
18
|
|
48
|
my ($self, $format, @args) = @_; |
113
|
|
|
|
|
|
|
|
114
|
18
|
|
|
|
|
114
|
return sprintf($format, @args); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub named_sprintf |
119
|
|
|
|
|
|
|
{ |
120
|
2
|
|
|
2
|
1
|
733
|
my ($format, @args) = @_; |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
3
|
my $params; |
123
|
2
|
50
|
|
|
|
8
|
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
|
|
|
|
|
3
|
$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__ |