Array-RefElem-1.00/0040755000076400007640000000000007770272502013041 5ustar gislegisleArray-RefElem-1.00/README0100644000076400007640000000044107036076470013716 0ustar gislegisleArray::RefElem This module give direct access to the internal perl routines that let you store reference to things in arrays and hashes. Copyright 2000 Gisle Aas This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Array-RefElem-1.00/Makefile.PL0100644000076400007640000000025607036040520014777 0ustar gislegisleuse ExtUtils::MakeMaker; WriteMakefile( NAME => 'Array::RefElem', VERSION_FROM => 'RefElem.pm', dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, ); Array-RefElem-1.00/Changes0100644000076400007640000000070607770272366014344 0ustar gislegisle2003-12-18 Gisle Aas Release 1.00 Documentation fixes by Paul Croome . 2000-01-13 Gisle Aas Release 0.02 Do reference counting for av_store/hv_store the right way. Previously we could trigger a core dump if the thing to be stored only was kept alive by a reference at the same location in the array. 2000-01-10 Gisle Aas Release 0.01 Array-RefElem-1.00/RefElem.xs0100644000076400007640000000217607037443574014744 0ustar gislegisle#ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif MODULE = Array::RefElem PACKAGE = Array::RefElem void av_store(avref, key, val) SV* avref I32 key SV* val PROTOTYPE: \@$$ PREINIT: AV* av; CODE: if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV) croak("First argument to av_store() must be an array reference"); av = (AV*)SvRV(avref); SvREFCNT_inc(val); if (!av_store(av, key, val)) SvREFCNT_dec(val); void av_push(avref, val) SV* avref SV* val PROTOTYPE: \@$ PREINIT: AV* av; CODE: if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV) croak("First argument to av_push() must be an array reference"); av = (AV*)SvRV(avref); SvREFCNT_inc(val); av_push(av, val); void hv_store(hvref, key, val) SV* hvref SV* key SV* val PROTOTYPE: \%$$ PREINIT: HV* hv; CODE: if (!SvROK(hvref) || SvTYPE(SvRV(hvref)) != SVt_PVHV) croak("First argument to hv_store() must be a hash reference"); hv = (HV*)SvRV(hvref); SvREFCNT_inc(val); if (!hv_store_ent(hv, key, val, 0)) SvREFCNT_dec(val); Array-RefElem-1.00/MANIFEST0100644000076400007640000000010607036076500014157 0ustar gislegisleChanges MANIFEST Makefile.PL README RefElem.pm RefElem.xs t/refelem.t Array-RefElem-1.00/t/0040755000076400007640000000000007770272502013304 5ustar gislegisleArray-RefElem-1.00/t/refelem.t0100644000076400007640000000121407037444042015077 0ustar gislegisleprint "1..5\n"; use strict; use Array::RefElem qw(av_store av_push hv_store); my $a = "a"; my @a = (1, 2, 3, 4); av_store(@a, 1, $a); av_push(@a, $a); print "not " unless "@a" eq "1 a 3 4 a"; print "ok 1\n"; $a = 2; print "not " unless "@a" eq "1 2 3 4 2"; print "ok 2\n"; $a[1] = "z"; print "not " unless $a[4] eq "z"; print "ok 3\n"; my %h; hv_store(%h, "foo", $a); $h{foo} = "bar"; print "not " unless $a eq "bar"; print "ok 4\n"; $a[2] = [3]; av_store(@a, 2, $a[2][0]); print "not " unless $a[2] == 3; print "ok 5\n"; if (shift) { require Devel::Peek; Devel::Peek::Dump($a); Devel::Peek::Dump(\@a); Devel::Peek::Dump(\%h); } Array-RefElem-1.00/RefElem.pm0100644000076400007640000000243407770272313014716 0ustar gislegislepackage Array::RefElem; use strict; use vars qw(@ISA @EXPORT_OK $VERSION); require Exporter; require DynaLoader; @ISA = qw(Exporter DynaLoader); @EXPORT_OK = qw(av_store av_push hv_store); $VERSION = '1.00'; Array::RefElem->bootstrap($VERSION); 1; __END__ =head1 NAME Array::RefElem - Set up array elements as aliases =head1 SYNOPSIS use Array::RefElem qw(av_store av_push hv_store); av_store(@a, 1, $a); av_push(@a, $a); hv_store(%h, $key, $a); =head1 DESCRIPTION This module gives direct access to some of the internal Perl routines that let you store things in arrays and hashes. The following functions are available: =over =item av_store(@array, $index, $value) Stores $value in @array at the specified $index. After executing this call, $array[$index] and $value denote the same thing. =item av_push(@array, $value) Pushes $value onto the @array. After executing this call, $array[-1] and $value denote the same thing. =item hv_store(%hash, $key, $value); Stores $value in the %hash with the given $key. After executing this call, $hash{$key} and $value denote the same thing. =back =head1 SEE ALSO L =head1 COPYRIGHT Copyright 2000 Gisle Aas. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut