line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Readonly::Enum; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22998
|
use v5.10; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
941
|
use version 0.77; our $VERSION = version->declare("v0.1.4"); |
|
1
|
|
|
|
|
2226
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
954
|
use Scalar::Readonly qw/ readonly_on /; |
|
1
|
|
|
|
|
824
|
|
|
1
|
|
|
|
|
252
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Enum - enumerated scalar values |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Readonly::Enum; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# $foo = 1, $bar = 2, etc. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Readonly::Enum my ($foo, $bar, $baz); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# $foo = 0, $bar = 1, etc. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Readonly::Enum my ($foo, $bar, $baz) => 0; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# $foo = 0, $bar = 5, $baz = 6, etc. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Readonly::Enum my ($foo, $bar, $baz) => (0, 5); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This module provides some syntactic sugar for defining enumerated |
35
|
|
|
|
|
|
|
scalar values. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
It is to L what the L package is to L. |
38
|
|
|
|
|
|
|
Unlike enumerated constants, these scalars can be used as hash keys |
39
|
|
|
|
|
|
|
and interpolated in strings. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Unlike L, only integers are supported in this version. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 STATUS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This module is no longer maintained. See L for |
46
|
|
|
|
|
|
|
similar functionality. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 AUTHOR |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Robert Rothenberg C. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Copyright 2013-2014 Robert Rothenberg. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
57
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
58
|
|
|
|
|
|
|
copy of the full license at: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
L |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
63
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
64
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
65
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
68
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
69
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
72
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
75
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
76
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
77
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
78
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
79
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
80
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
81
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
84
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
85
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
86
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
87
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
88
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
89
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
90
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub Readonly::Enum { |
95
|
|
|
|
|
|
|
|
96
|
3
|
|
|
3
|
|
1303
|
my @vals = grep { defined $_ } @_; |
|
12
|
|
|
|
|
26
|
|
97
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
6
|
my $i = 0; |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
4
|
my $start = 0; |
101
|
|
|
|
|
|
|
|
102
|
3
|
|
|
|
|
14
|
for($i=0; $i<@_; $i++) { |
103
|
|
|
|
|
|
|
|
104
|
11
|
100
|
|
|
|
26
|
last if defined $_[$i]; |
105
|
|
|
|
|
|
|
|
106
|
9
|
100
|
|
|
|
16
|
$start = @vals ? (shift @vals) : ++$start; |
107
|
|
|
|
|
|
|
|
108
|
9
|
|
|
|
|
29
|
readonly_on($_[$i] = $start); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |