line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::Roman; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24998
|
use v5.10; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
52
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
46
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
932
|
use Math::Roman; |
|
1
|
|
|
|
|
53816
|
|
|
1
|
|
|
|
|
60
|
|
8
|
1
|
|
|
1
|
|
997
|
use Template::Plugin::Filter; |
|
1
|
|
|
|
|
14975
|
|
|
1
|
|
|
|
|
39
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
12
|
use base qw( Template::Plugin::Filter ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
277
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Template::Plugin::Roman - Filter for converting Arabic numerals to Roman |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 1.0 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '1.0'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This module provides a Template::Toolkit filter plugin for converting Arabic |
28
|
|
|
|
|
|
|
numerals into Roman. The actual conversion is performed by Math::Roman. The |
29
|
|
|
|
|
|
|
same restrictions imposed by that module are in effect here (4499 is the largest |
30
|
|
|
|
|
|
|
"real" Roman number - everything after that will simply have too many 'M's). |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Using the filter is straightforward (assume that your controller has placed |
33
|
|
|
|
|
|
|
C<(localtime)[5]> in a stash key called C): |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
[% USE Roman %] |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The year is [% current_year | roman %]. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 init |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Initialize filter object. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub init { |
48
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->{_DYNAMIC} = 1; |
51
|
0
|
|
|
|
|
|
$self->install_filter('roman'); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return $self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 filter |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Implement filter. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub filter { |
63
|
0
|
|
|
0
|
1
|
|
my ($self, $text) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
return $text unless $text =~ m{^\d+$}o; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $roman = Math::Roman->new($text); |
68
|
0
|
|
|
|
|
|
return "$roman"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Jon Sime, C<< >> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SUPPORT |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
perldoc Template::Plugin::Roman |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
You can also look for information at: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item * GitHub Repository |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This plugin is a pretty thin wrapper around C which does |
96
|
|
|
|
|
|
|
all the real work of converting numerals. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright 2013 Jon Sime. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
103
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
104
|
|
|
|
|
|
|
copy of the full license at: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
109
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
110
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
111
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
114
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
115
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
118
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
121
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
122
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
123
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
124
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
125
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
126
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
127
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
130
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
131
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
132
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
133
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
134
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
135
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
136
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |