The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tie::Symbol - Tied interface to the symbol table

VERSION

version 0.001

SYNOPSIS

    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

DESCRIPTION

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.

Tied hash

    tie my %hash, 'Tie::Symbol', $package;

The hash is tied to a specific namespace or the main package if no package is given.

Examine

    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'};

METHODS

namespace

Returns the current namespace

    $ST->namespace;

Thats in short just whats given as package name to "new"

parent_namespace

Return the name of the parent namespace.

    my $parent_ns = $ST->parent_namespace;

Returns undef if there is no parent namespace

parent

Like "parent_namespace" but return an instance of Tie::Symbol.

    my $parent = $ST->parent;
    my $parent_ns = $parent->namespace;

Returns undef if there is no parent namespace

Search for a symbol with a regular expression

    my @zzz = $ST->search(qr{zzz});

scalars

Returns a list of all scalars

    my @scalars = $ST->scalars;

hashes

Returns a list of all hashes

    my @hashes = $ST->hashes;

arrays

Returns a list of all arrays

    my @arrays = $ST->arrays;

subs

Returns a list of all subroutines

    my @subs = $ST->subs;

classes

Returns a list of all subclasses in namespace

    my @classes = $ST->classes;

tree

Returns a recursive HashRef with all subclasses of a namespace

    my $tree = $ST->tree;

new

Returns a blessed reference to a tied hash of ourselves.

    my $ST = Tie::Symbol->new;

mine

Return the symbol table of the caller's scope.

    my $my_symbol_table = Tie::Symbol->mine;

Dumping

    tie my %ST, 'Tie::Symbol', 'PKG';
    my @symbols = keys %ST;

Existence

    exists $ST{'&code'} ? 'code exists' : 'code dont exists'

Caveat: existence checks on scalars and namespaces always returns true.

Modify

    $ST{'&code'} = sub { ... };
    $ST{'$scalar'} = \"...";
    $ST{'@array'} = [ ... ];
    $ST{'%hash'} = { ... };

Erasing

    sub PKG::abc { ... }
    tie my %ST, 'Tie::Symbol', 'PKG';
    PKG::abc(); # works
    my $abc = delete $ST{'&abc'};
    PKG::abc(); # croaks
    $abc->(); # subroutine survived anonymously!

Clearing

    tie my %ST, 'Tie::Symbol', 'PKG';
    %ST = ();

BUGS

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.

AUTHOR

David Zurborg <zurborg@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by David Zurborg.

This is free software, licensed under:

  The ISC License