| 1 | package Devel::Spy::TieArray; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use constant SELF => 0; | ||
| 5 | use constant IX => 1; | ||
| 6 | use constant COUNT => 1; | ||
| 7 | use constant VALUE => 2; | ||
| 8 | |||
| 9 | use constant PAYLOAD => 0; | ||
| 10 | use constant CODE => 1; | ||
| 11 | |||
| 12 | sub TIEARRAY { | ||
| 13 | my ( undef, @array ) = @_; | ||
| 14 | return bless \ @array, $_[SELF]; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub FETCH { | ||
| 18 | my $followup = $_[SELF][CODE]->(' ->['.(defined $_[IX] ? $_[IX] : 'undef').']'); | ||
| 19 | my $ix = defined $_[IX] ? $_[IX] : 0; | ||
| 20 | my $value = $_[SELF][PAYLOAD][$ix]; | ||
| 21 | $followup = $followup->(' ->'.(defined $value ? $value : 'undef')); | ||
| 22 | return Devel::Spy->new( $value, $followup ); | ||
| 23 | } | ||
| 24 | |||
| 25 | sub STORE { | ||
| 26 | my $followup = $_[SELF][CODE]->(' ->['.(defined $_[IX] ? $_[IX] : 'undef').'] = '.(defined $_[VALUE] ? $_[VALUE] : 'undef')); | ||
| 27 | my $ix = defined $_[IX] ? $_[IX] : 0; | ||
| 28 | $_[SELF][PAYLOAD]->[$ix] = $_[VALUE]; | ||
| 29 | return Devel::Spy->new( $_[VALUE], $followup ); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub FETCHSIZE { | ||
| 33 | my $followup = $_[SELF][CODE]->(' scalar(@...)'); | ||
| 34 | my $value = @{ $_[SELF][PAYLOAD] }; | ||
| 35 | $followup = $_[SELF][CODE]->(' ->'.(defined $value ? $value : 'undef')); | ||
| 36 | return Devel::Spy->new( $value, $followup ); | ||
| 37 | } | ||
| 38 | |||
| 39 | sub STORESIZE { | ||
| 40 | $_[SELF][CODE]->(' $#... = ' . (defined $_[COUNT] ? $_[COUNT] : 'undef' )); | ||
| 41 | $#{ $_[SELF][PAYLOAD] } = defined $_[COUNT] ? 1 + $_[COUNT] : 0; | ||
| 42 | return; | ||
| 43 | } | ||
| 44 | |||
| 45 | # sub EXTEND { | ||
| 46 | # my ( $self, $count ) = @_; | ||
| 47 | # | ||
| 48 | # } | ||
| 49 | # | ||
| 50 | # sub EXISTS { | ||
| 51 | # | ||
| 52 | # } | ||
| 53 | # | ||
| 54 | # sub DELETE { } | ||
| 55 | # | ||
| 56 | # sub CLEAR { } | ||
| 57 | # | ||
| 58 | # sub PUSH { } | ||
| 59 | # | ||
| 60 | # sub POP { } | ||
| 61 | # | ||
| 62 | # sub SHIFT { } | ||
| 63 | # sub UNSHIFT { } | ||
| 64 | # sub SPLICE { } | ||
| 65 | |||
| 66 | sub UNTIE {} | ||
| 67 | sub DESTROY {} | ||
| 68 | |||
| 69 | 1; | ||
| 70 | |||
| 71 | __END__ |