File Coverage

blib/lib/Type/Tie/Aggregate/Scalar.pm
Criterion Covered Total %
statement 26 26 100.0
branch 3 4 75.0
condition n/a
subroutine 9 9 100.0
pod n/a
total 38 39 97.4


line stmt bran cond sub pod time code
1             # ABSTRACT: class to tie arrays for Type::Tie::Aggregate
2              
3             ######################################################################
4             # Copyright (C) 2021 Asher Gordon #
5             # #
6             # This program is free software: you can redistribute it and/or #
7             # modify it under the terms of the GNU General Public License as #
8             # published by the Free Software Foundation, either version 3 of #
9             # the License, or (at your option) any later version. #
10             # #
11             # This program is distributed in the hope that it will be useful, #
12             # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
14             # General Public License for more details. #
15             # #
16             # You should have received a copy of the GNU General Public License #
17             # along with this program. If not, see #
18             # . #
19             ######################################################################
20              
21             package Type::Tie::Aggregate::Scalar;
22             $Type::Tie::Aggregate::Scalar::VERSION = '0.001';
23             #pod =head1 DESCRIPTION
24             #pod
25             #pod This class is used to tie arrays. This class is internal to
26             #pod L.
27             #pod
28             #pod The C<_value> method is overloaded to return and set the referenced
29             #pod scalar, rather than the reference itself. C<< $obj->_value >> is like
30             #pod C<< ${$obj->_ref} >>.
31             #pod
32             #pod =cut
33              
34 5     5   86 use v5.6.0;
  5         18  
35 5     5   28 use strict;
  5         10  
  5         113  
36 5     5   26 use warnings;
  5         12  
  5         172  
37 5     5   29 use namespace::autoclean;
  5         20  
  5         42  
38 5     5   428 use Carp;
  5         20  
  5         394  
39 5     5   34 use parent 'Type::Tie::Aggregate::Base';
  5         12  
  5         32  
40              
41             sub _create_ref {
42 6     6   13 shift;
43 6 50       22 carp 'More than one value given for scalar; using first value'
44             if @_ > 1;
45 6         26 \$_[0];
46             }
47              
48             sub _value {
49 24     24   46 my $self = shift;
50 24         54 my $ref = $self->_ref;
51 24 100       100 return $$ref unless @_;
52 11         32 ($$ref) = @_;
53             }
54              
55 4     4   11 sub TIESCALAR { my $class = shift; $class->_new(@_) }
  4         29  
56              
57             __PACKAGE__->_install_methods(
58             { mutates => 1 },
59             STORE => '$$ref = $_[0]',
60             );
61              
62             __PACKAGE__->_install_methods(
63             { mutates => 0 },
64             FETCH => '$$ref',
65             );
66              
67             #pod =head1 SEE ALSO
68             #pod
69             #pod =for :list
70             #pod * L
71             #pod
72             #pod =cut
73              
74             1;
75              
76             __END__