Tie::Symbol - Tied interface to the symbol table
version 0.001
sub abc { 123 }; my $ST = Tie::Symbol->new; my $abc = $ST->{'&abc'}; $abc->(); # returns 123 $ST->{'&abc'} = sub { 456 }; abc(); # returns 456 tie(my %ST, 'Tie::Symbol'); $ST{'&abc'}; # see above
The tied hash represents the internal symbol table which allows the user to examine and modify the whole symbol table.
Currently this implementation limits the referents to scalars, arrays, hashes and subroutines.
tie my %hash, 'Tie::Symbol', $package;
The hash is tied to a specific namespace or the main package if no package is given.
our $PKG::scalar = 123; tie my %ST, 'Tie::Symbol', 'PKG'; my $ScalarRef = $ST{'$scalar'}; package X::Y { sub z { ... } } my $ST = Tie::Symbol->new; my $z = $ST->{X}->{Y}->{'&z'}; my $z = $ST->{'X::Y'}->{'&z'}; my $z = $ST->{'&X::Y::z'};
Returns the current namespace
$ST->namespace;
Thats in short just whats given as package name to "new"
Return the name of the parent namespace.
my $parent_ns = $ST->parent_namespace;
Returns undef if there is no parent namespace
undef
Like "parent_namespace" but return an instance of Tie::Symbol.
my $parent = $ST->parent; my $parent_ns = $parent->namespace;
Search for a symbol with a regular expression
my @zzz = $ST->search(qr{zzz});
Returns a list of all scalars
my @scalars = $ST->scalars;
Returns a list of all hashes
my @hashes = $ST->hashes;
Returns a list of all arrays
my @arrays = $ST->arrays;
Returns a list of all subroutines
my @subs = $ST->subs;
Returns a list of all subclasses in namespace
my @classes = $ST->classes;
Returns a recursive HashRef with all subclasses of a namespace
my $tree = $ST->tree;
Returns a blessed reference to a tied hash of ourselves.
my $ST = Tie::Symbol->new;
Return the symbol table of the caller's scope.
my $my_symbol_table = Tie::Symbol->mine;
tie my %ST, 'Tie::Symbol', 'PKG'; my @symbols = keys %ST;
exists $ST{'&code'} ? 'code exists' : 'code dont exists'
Caveat: existence checks on scalars and namespaces always returns true.
$ST{'&code'} = sub { ... }; $ST{'$scalar'} = \"..."; $ST{'@array'} = [ ... ]; $ST{'%hash'} = { ... };
sub PKG::abc { ... } tie my %ST, 'Tie::Symbol', 'PKG'; PKG::abc(); # works my $abc = delete $ST{'&abc'}; PKG::abc(); # croaks $abc->(); # subroutine survived anonymously!
tie my %ST, 'Tie::Symbol', 'PKG'; %ST = ();
Please report any bugs or feature requests on the bugtracker website https://github.com/zurborg/libtie-symbol-perl/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
David Zurborg <zurborg@cpan.org>
This software is Copyright (c) 2015 by David Zurborg.
This is free software, licensed under:
The ISC License
To install Tie::Symbol, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Symbol
CPAN shell
perl -MCPAN -e shell install Tie::Symbol
For more information on module installation, please visit the detailed CPAN module installation guide.