our
$VERSION
=
'0.29'
;
*dump_scalar
= \
&Devel::DumpTrace::dump_scalar
;
sub
TIEARRAY {
my
(
$class
,
@list
) =
@_
;
my
$self
= {
CACHE
=> {},
ARRAY
=> [
@list
],
PARRAY
=> [
map
{ dump_scalar(
$_
) }
@list
]
};
return
bless
$self
,
$class
;
}
sub
FETCH {
my
(
$self
,
$index
) =
@_
;
return
$self
->{ARRAY}[
$index
];
}
sub
STORE {
my
(
$self
,
$index
,
$value
) =
@_
;
$self
->clear_cache;
my
$old
=
$self
->{ARRAY}[
$index
];
$self
->{ARRAY}[
$index
] =
$value
;
$self
->{PARRAY}[
$index
] = dump_scalar(
$value
);
return
$old
;
}
sub
FETCHSIZE {
my
$self
=
shift
;
return
scalar
@{
$self
->{ARRAY}};
}
sub
STORESIZE {
my
(
$self
,
$newcount
) =
@_
;
my
$oldcount
=
$self
->FETCHSIZE();
if
(
$newcount
>
$oldcount
) {
$self
->clear_cache;
$self
->STORE(
$_
,
undef
)
for
$oldcount
..
$newcount
-1;
}
elsif
(
$newcount
<
$oldcount
) {
$self
->clear_cache;
$self
->POP()
for
$newcount
..
$oldcount
-1;
}
return
;
}
sub
EXTEND {
return
;
}
sub
DELETE {
my
(
$self
,
$index
) =
@_
;
$self
->clear_cache;
return
$self
->STORE(
$index
,
undef
);
}
sub
CLEAR {
my
$self
=
shift
;
$self
->clear_cache;
$self
->{PARRAY} = [];
$self
->{ARRAY} = [];
return
;
}
sub
EXISTS {
my
(
$self
,
$index
) =
@_
;
return
exists
$self
->{ARRAY}[
$index
];
}
sub
PUSH {
my
(
$self
,
@list
) =
@_
;
if
(
@list
> 0) {
$self
->clear_cache;
}
push
@{
$self
->{ARRAY}},
@list
;
push
@{
$self
->{PARRAY}},
map
{ dump_scalar(
$_
) }
@list
;
return
$self
->FETCHSIZE();
}
sub
POP {
my
$self
=
shift
;
if
(@{
$self
->{ARRAY}} > 0) {
$self
->clear_cache;
}
pop
@{
$self
->{PARRAY}};
return
pop
@{
$self
->{ARRAY}};
}
sub
SHIFT {
my
$self
=
shift
;
if
(@{
$self
->{ARRAY}} > 0) {
$self
->clear_cache;
}
shift
@{
$self
->{PARRAY}};
return
shift
@{
$self
->{ARRAY}};
}
sub
UNSHIFT {
my
(
$self
,
@list
) =
@_
;
if
(
@list
> 0) {
$self
->clear_cache;
}
unshift
@{
$self
->{PARRAY}},
map
{ dump_scalar(
$_
) }
@list
;
my
$result
=
unshift
@{
$self
->{ARRAY}},
@list
;
return
$result
;
}
sub
SPLICE {
my
(
$self
,
$offset
,
$length
,
@list
) =
@_
;
$offset
||= 0;
$length
||=
$self
->FETCHSIZE() -
$offset
;
$self
->clear_cache;
splice
@{
$self
->{PARRAY}},
$offset
,
$length
,
map
{ dump_scalar(
$_
) }
@list
;
return
splice
@{
$self
->{ARRAY}},
$offset
,
$length
,
@list
;
}
sub
clear_cache {
my
$self
=
shift
;
$self
->{CACHE} = {};
return
;
}
sub
store_cache {
my
(
$self
,
$key
,
$value
) =
@_
;
$self
->{CACHE}{
$key
} =
$value
;
return
;
}
sub
get_cache {
my
(
$self
,
$key
) =
@_
;
return
$self
->{CACHE}{
$key
};
}
sub
is {
my
(
$pkg
,
$arrayref
) =
@_
;
return
tied
(
@$arrayref
) &&
ref
(
tied
(
@$arrayref
)) eq
$pkg
;
}
1;