Dynamizer/Tie.pm

filter: Statementstmt 92.3% 12 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod n/a totaltotal 88.8% 16 / 18 CC 1 SCAR 1.8
CC
1
Cov
92%
STORE
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Dynamizer.pm ↑ Summary
1 package Scalar::Dynamizer::Tie;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶sub TIESCALAR {
Subroutine TIESCALAR: called CC=1 SCAR=0.0
7 2 my ( $class, $code ) = @_;
8 2 return bless { code => $code }, $class;
9 }
10  
11 6 ▶sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
12 6 my ($self) = @_;
13 6 return $self->{code}->();
14 }
15  
16 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
17 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 2 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<Scalar::Dynamizer> to implement the tied scalar behavior.
36  
37 =head1 DESCRIPTION
38  
39 C<Scalar::Dynamizer::Tie> 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<TIESCALAR> 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<Scalar::Dynamizer> instead.
92  
93 =head1 AUTHOR
94  
95 Jeremi Gosney, C<< <epixoip at cpan.org> >>
96  
97 =head1 BUGS
98  
99 Please report any bugs or feature requests to C<bug-scalar-dynamizer at rt.cpan.org>,
100 or through the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Scalar-Dynamizer>.
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<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Scalar-Dynamizer>
117  
118 =item * CPAN Ratings
119  
120 L<https://cpanratings.perl.org/d/Scalar-Dynamizer>
121  
122 =item * Search CPAN
123  
124 L<https://metacpan.org/release/Scalar-Dynamizer>
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 2 1; # End of Scalar::Dynamizer::Tie
« Dynamizer.pm ↑ Summary