| 1 | ################################################################################ |
| 2 | # |
| 3 | # Copyright (c) Marcus Holland-Moritz. All rights reserved. |
| 4 | # This program is free software; you can redistribute it and/or modify |
| 5 | # it under the same terms as Perl itself. |
| 6 | # |
| 7 | ################################################################################ |
| 8 | |
| 9 | use Testscip-perl cpan Tie-Hash-Indexed 0.08 Test/; |
| 10 | |
| 11 | BEGIN { planscip-perl cpan Tie-Hash-Indexed 0.08 main/plan(). tests => 10 }; |
| 12 | |
| 13 | use Tie::Hash::Indexedscip-perl cpan Tie-Hash-Indexed 0.08 Tie/Hash/Indexed/; |
| 14 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().(1); |
| 15 | |
| 16 | tie my $c, 'MagicScalar', 42; |
| 17 | |
| 18 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($MagicScalar::GLOBALscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/$GLOBAL., 42); |
| 19 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($c, 42); |
| 20 | $c = 13; |
| 21 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($MagicScalar::GLOBALscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/$GLOBAL., 13); |
| 22 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($c, 13); |
| 23 | |
| 24 | my $h = Tie::Hash::Indexed->newscip-perl cpan Tie-Hash-Indexed 0.08 Tie/Hash/Indexed/new().(foo => 1, bar => 2, zoo => 3, baz => 4); |
| 25 | |
| 26 | $h->setscip-perl cpan Tie-Hash-Indexed 0.08 Tie/Hash/Indexed/set().('foo', $c); |
| 27 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($h->getscip-perl cpan Tie-Hash-Indexed 0.08 Tie/Hash/Indexed/get().('foo'), 13); |
| 28 | |
| 29 | $h->addscip-perl cpan Tie-Hash-Indexed 0.08 Tie/Hash/Indexed/add().('foo', ++$c); |
| 30 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($h->getscip-perl cpan Tie-Hash-Indexed 0.08 Tie/Hash/Indexed/get().('foo'), 27); |
| 31 | |
| 32 | my %h2; |
| 33 | $h2{foo} = $c; |
| 34 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($h2{foo}, 14); |
| 35 | |
| 36 | $c++; |
| 37 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($h2{foo}, 14); |
| 38 | |
| 39 | tie $h2{foo}, 'MagicScalar'; |
| 40 | okscip-perl cpan Tie-Hash-Indexed 0.08 main/ok().($h2{foo}, 15); |
| 41 | |
| 42 | package MagicScalarscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/; |
| 43 | |
| 44 | use varsscip-perl cpan Tie-Hash-Indexed 0.08 vars/ qw( $GLOBAL ); |
| 45 | |
| 46 | sub TIESCALARscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/TIESCALAR(). { $GLOBALscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/$GLOBAL. = $_scip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/`@_`.[1] if @_scip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/`@_`. > 1; blessscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/bless(). [], $_scip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/`@_`.[0] } |
| 47 | sub FETCHscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/FETCH(). { $GLOBALscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/$GLOBAL. } |
| 48 | sub STOREscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/STORE(). { $GLOBALscip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/$GLOBAL. = $_scip-perl cpan Tie-Hash-Indexed 0.08 MagicScalar/`@_`.[1] } |
| 49 |