blib/lib/Tie/Scalar/Epoch.pm

filter: Statementstmt 100% 25 / 25 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 92.5% 37 / 40 CC 4 SCAR 5.5
CC
4
Cov
94%
STORE
3.0
TIESCALAR
2.0
BEGIN
1.0
CRAP 1.7
↑ Summary
1 package Tie::Scalar::Epoch;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base qw(Tie::Scalar);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 $VERSION = '0.01';
11  
12 1 ▶sub TIESCALAR {
Subroutine TIESCALAR: called CC=2 SCAR=7.1
13 1 my $class = shift;
14 1 ▶ my $options = shift || {};
Condition50%1/2
shift() || {}
l!l
01
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
15 1 return bless $options, $class;
16 }
17  
18 2 ▶sub STORE {
Subroutine STORE: called CC=3 SCAR=11.1
19 2 my $self = shift;
20 # die unless asked not to (by having no_die in the tie statement)
21 2 ▶ croak "Can't store to a Tie::Scalar::Epoch variable" unless $self->{no_die};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_die"} 1 1 2
22 1 ▶ carp "Can't store to a Tie::Scalar::Epoch variable" if $^W;
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 1 1
23 }
24  
25 2 ▶sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
26 2 my $self = shift;
27 2 return time;
28 }
29  
30 # module return
31 1 1;
32  
33 =head1 NAME
34  
35 Tie::Scalar::Epoch - Create a scalar that always returns the number
36 of non-leap seconds since whatever time the system considers to be the epoch.
37  
38 =head1 SYNOPSIS
39  
40 # create a variable and tie
41 tie my $epoch, 'Tie::Scalar::Epoch';
42
43 print "$epoch\n"; # eg. 1351113480
44 sleep 2; # wait 2 seconds...
45 print "$epoch\n"; # ... 1351113482
46
47 # this will die; $epoch is a readonly variable
48 $epoch = '2012';
49  
50 # don't die if no_die is true
51 tie my $epoch, 'Tie::Scalar::Epoch', { no_die => 1 };
52 $epoch = '2012';
53
54
55 =head1 DESCRIPTION
56  
57 This is a B<very> simple class that creates readonly scalars
58 that always return the current epoch.
59  
60 A variables tied to this class is readonly, and attempting to
61 assign to it will raise an exception.
62  
63 =head1 OPTIONS
64  
65 The following options can be passed in a hashref to C<tie>.
66  
67 =over
68  
69 =item C<no_die>
70  
71 Do not throw an exception when attempting to assign to a
72 tied scalar. This module will still emit a warning if you
73 have warnings enabled.
74  
75 =back
76  
77 =head1 SEE ALSO
78  
79 L<perltie>, L<Tie::Scalar>,
80  
81 =head1 AUTHOR
82  
83 Victor Houston, C<< <vichouston@cpan.org> >>
84  
85 =head1 COPYRIGHT AND LICENSE
86  
87 Copyright E<copy>2012 by Victor Houston.
88
89 This program is free software; you can redistribute it
90 and/or modify it under the same terms as Perl itself.
91  
92 =cut
↑ Summary