| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | # XML::Axk::Vars::Array - tie an array to a member in X::A::Core. | ||||||||||
| 3 | # Copyright (c) 2018 cxw42. All rights reserved. Artistic 2. | ||||||||||
| 4 | |||||||||||
| 5 | package XML::Axk::Vars::Array; | ||||||||||
| 6 | 2 | ▶ | use XML::Axk::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Tie::Array; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use parent -norequire => 'Tie::StdArray'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # Tie methods ==================================================== {{{1 | ||||||||||
| 12 | |||||||||||
| 13 | # Create an array tied to a script-accessible var in an XAC instance | ||||||||||
| 14 | # @param $class | ||||||||||
| 15 | # @param $core XML::Axk::Core instance | ||||||||||
| 16 | # @param $varname Name of the new variable | ||||||||||
| 17 | sub TIEARRAY { | ||||||||||
| 18 | 0 | ▶ | my $class = shift; | ||||||||
|
Subroutine
TIEARRAY: not called CC=5 SCAR=34.0
| |||||||||||
| 19 | 0 | ▶ | croak("Internal use only --- see XML::Axk::Sandbox") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | unless scalar caller eq 'XML::Axk::Sandbox'; | ||||||||||
| 21 | |||||||||||
| 22 | 0 | my ($sandbox, $lang, $varname) = @_; | |||||||||
| 23 | 0 | ▶ | croak 'No sandbox' unless ref $sandbox eq 'XML::Axk::Sandbox'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | ▶ | croak 'No language name' unless $lang; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | ▶ | croak 'No varname' unless $varname; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | #say "Tying array \$$varname to $core"; | ||||||||||
| 28 | 0 | my $hrSP = $sandbox->sps($lang); | |||||||||
| 29 | 0 | return bless $hrSP->{$varname}, $class; | |||||||||
| 30 | } #TIEARRAY() | ||||||||||
| 31 | |||||||||||
| 32 | # }}}1 | ||||||||||
| 33 | 2 | 1; | |||||||||
| 34 | # vi: set ts=4 sts=4 sw=4 et ai fo-=ro foldmethod=marker foldlevel=2: # | ||||||||||