blib/lib/Readonly/BeginLift.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Readonly::BeginLift;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use Devel::BeginLift ();
Subroutine BEGIN: called CC=1 SCAR=2.6
8 Devel::BeginLift->setup_for(
9 Readonly => [
10 qw(
11 Readonly
12 Scalar
13 Array
14 Hash
15 )
16 ]
17 );
18  
19 use parent 'Exporter';
20 our @EXPORT = 'Readonly';
21 our @EXPORT_OK = qw/Scalar Array Hash Scalar1 Array1 Hash1/;
22  
23 =head1 NAME
24  
25 Readonly::BeginLift - Readonly at BEGIN time
26  
27 =head1 VERSION
28  
29 Version 0.03
30  
31 =cut
32  
33 our $VERSION = '0.03';
34  
35 =head1 SYNOPSIS
36  
37 use Readonly::BeginLift;
38 Readonly my $VAR => 'foo';
39 Readonly::Scalar my $VAR2 => 'bar';
40 BEGIN { print $VAR, $VAR2 }
41 __END__
42 foo,bar
43  
44 =head1 DESCRIPTION
45  
46 The L<Readonly> module exports the C<Readonly> subroutine, but this subroutine
47 executes at runtime. This module causes it to execute at BEGIN time. Thus:
48  
49 use strict;
50 use warnings;
51 use Readonly;
52 use constant MY_VALUE => 'foo';
53 Readonly my $MY_VALUE => 'bar';
54  
55 BEGIN {
56 print MY_VALUE, "\n";
57 print $MY_VALUE, "\n";
58 }
59  
60 That will print "foo" and issue an uninitialized value warning. One way to
61 make it work is to do this:
62  
63 use strict;
64 use warnings;
65 use Readonly;
66 use constant MY_VALUE => 'foo';
67 my $MY_VALUE;
68  
69 BEGIN {
70 Readonly my $MY_VALUE => 'bar';
71 print MY_VALUE, "\n";
72 print $MY_VALUE, "\n";
73 }
74
75 That's a bit clumsy, so we use C<Devel::BeginLift> to make C<Readonly> execute
76 at begin time.
77  
78 =head1 EXPORT
79  
80 =head2 C<Readonly>
81  
82 This is identical to the L<Readonly> module, except that it happens at BEGIN
83 time.
84  
85 =head1 AUTHOR
86  
87 Curtis "Ovid" Poe, C<< <ovid at cpan.org> >>
88  
89 =head1 BUGS
90  
91 Please report any bugs or feature requests to C<bug-readonly-beginlift at
92 rt.cpan.org>, or through the web interface at
93 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Readonly-BeginLift>. I will
94 be notified, and then you'll automatically be notified of progress on your bug
95 as I make changes.
96  
97 =head1 SUPPORT
98  
99 You can find documentation for this module with the perldoc command.
100  
101 perldoc Readonly::BeginLift
102  
103 You can also look for information at:
104  
105 =over 4
106  
107 =item * RT: CPAN's request tracker
108  
109 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Readonly-BeginLift>
110  
111 =item * AnnoCPAN: Annotated CPAN documentation
112  
113 L<http://annocpan.org/dist/Readonly-BeginLift>
114  
115 =item * CPAN Ratings
116  
117 L<http://cpanratings.perl.org/d/Readonly-BeginLift>
118  
119 =item * Search CPAN
120  
121 L<http://search.cpan.org/dist/Readonly-BeginLift/>
122  
123 =back
124  
125 =head1 ACKNOWLEDGEMENTS
126  
127 Thanks for Florian Ragwitz for L<Devel::BeginLift>.
128  
129 =head1 COPYRIGHT & LICENSE
130  
131 Copyright 2010 Curtis "Ovid" Poe, all rights reserved.
132  
133 This program is free software; you can redistribute it and/or modify it
134 under the same terms as Perl itself.
135  
136 =cut
137  
138 1;
↑ Summary