File Coverage

blib/lib/Type/Tie/Aggregate/Array.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition n/a
subroutine 8 9 88.8
pod n/a
total 31 32 96.8


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::Array;
22             $Type::Tie::Aggregate::Array::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 =cut
29              
30 5     5   86 use v5.6.0;
  5         18  
31 5     5   30 use strict;
  5         8  
  5         149  
32 5     5   38 use warnings;
  5         12  
  5         186  
33 5     5   31 use namespace::autoclean;
  5         20  
  5         54  
34 5     5   409 use parent 'Type::Tie::Aggregate::Base';
  5         18  
  5         43  
35              
36 19     19   34 sub _create_ref { shift; \@_ }
  19         87  
37              
38             sub _check_value {
39 7     7   17 my (undef, $value) = @_;
40 7 100       25 return 'Not an ARRAY reference' unless ref $value eq 'ARRAY';
41 6         17 return;
42             }
43              
44 18     18   44 sub TIEARRAY { my $class = shift; $class->_new(@_) }
  18         104  
45              
46             __PACKAGE__->_install_methods(
47             { mutates => 1 },
48             STORESIZE => '$#$ref = $_[0] - 1',
49             STORE => '$ref->[$_[0]] = $_[1]',
50             CLEAR => '@$ref = ()',
51             POP => 'pop @$ref',
52             PUSH => 'push @$ref, @_',
53             SHIFT => 'shift @$ref',
54             UNSHIFT => 'unshift @$ref, @_',
55             SPLICE => '&CORE::splice($ref, @_)',
56             DELETE => 'delete $ref->[$_[1]]',
57             );
58              
59             __PACKAGE__->_install_methods(
60             { mutates => 0 },
61             FETCHSIZE => '@$ref',
62             FETCH => '$ref->[$_[0]]',
63             EXISTS => 'exists $ref->[$_[0]]',
64       0     EXTEND => sub {},
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__