File Coverage

blib/lib/Scalar/Dynamizer/Tie.pm
Criterion Covered Total %
statement 10 11 90.9
branch n/a
condition n/a
subroutine 4 5 80.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Scalar::Dynamizer::Tie;
2              
3 2     2   12 use strict;
  2         17  
  2         71  
4 2     2   15 use warnings;
  2         11  
  2         435  
5              
6             sub TIESCALAR {
7 2     2   3 my ( $class, $code ) = @_;
8 2         7 return bless { code => $code }, $class;
9             }
10              
11             sub FETCH {
12 6     6   11 my ($self) = @_;
13 6         18 return $self->{code}->();
14             }
15              
16             sub STORE {
17 0     0     croak('Cannot assign to a dynamic scalar');
18             }
19              
20             =head1 NAME
21              
22             Scalar::Dynamizer::Tie - Internal implementation for Scalar::Dynamizer
23              
24             =head1 VERSION
25              
26             Version 1.000
27              
28             =cut
29              
30             our $VERSION = 1.000;
31              
32             =head1 SYNOPSIS
33              
34             This module is not intended to be used directly. It is used internally by
35             L to implement the tied scalar behavior.
36              
37             =head1 DESCRIPTION
38              
39             C is a tied scalar class that computes a dynamic value
40             each time the scalar is accessed. The actual logic for computing the value is
41             provided via a code reference when the scalar is tied.
42              
43             =head1 METHODS
44              
45             =head2 TIESCALAR
46              
47             my $object = Scalar::Dynamizer::Tie->TIESCALAR($code);
48              
49             Constructor for the tied scalar. Takes a code reference as its argument, which
50             will be executed each time the scalar's value is accessed.
51              
52             =head3 Parameters
53              
54             =over
55              
56             =item * C<$code> (required)
57              
58             A code reference that computes the scalar's value on access.
59              
60             =back
61              
62             =head3 Returns
63              
64             A blessed object representing the tied scalar.
65              
66             =head2 FETCH
67              
68             my $value = $object->FETCH();
69              
70             This method is called whenever the tied scalar's value is accessed. It executes
71             the code reference provided during C to compute and return the current
72             value of the scalar.
73              
74             =head3 Returns
75              
76             The value computed by the code reference.
77              
78             =head2 STORE
79              
80             $object->STORE($value);
81              
82             This method is called whenever an attempt is made to assign a value to the tied
83             scalar. Since dynamic scalars are immutable, this method throws an exception.
84              
85             =head3 Throws
86              
87             Cannot assign to a dynamic scalar
88              
89             =head1 LIMITATIONS
90              
91             This class is not intended for direct use. Use L instead.
92              
93             =head1 AUTHOR
94              
95             Jeremi Gosney, C<< >>
96              
97             =head1 BUGS
98              
99             Please report any bugs or feature requests to C,
100             or through the web interface at L.
101             I will be notified, and then you'll automatically be notified of progress on your
102             bug as I make changes.
103              
104             =head1 SUPPORT
105              
106             You can find documentation for this module with the perldoc command.
107              
108             perldoc Scalar::Dynamizer::Tie
109              
110             You can also look for information at:
111              
112             =over 4
113              
114             =item * RT: CPAN's request tracker (report bugs here)
115              
116             L
117              
118             =item * CPAN Ratings
119              
120             L
121              
122             =item * Search CPAN
123              
124             L
125              
126             =back
127              
128             =head1 LICENSE AND COPYRIGHT
129              
130             This software is Copyright (c) 2025 by Jeremi Gosney.
131              
132             This is free software, licensed under:
133              
134             The Artistic License 2.0 (GPL Compatible)
135              
136             =cut
137              
138             1; # End of Scalar::Dynamizer::Tie