NAME

Symbol::Util - Additional utils for Perl symbols manipulation

SYNOPSIS

use Symbol::Util ':all';

my $caller = caller;
*{ fetch_glob("${caller}::foo") } = sub { "this is foo" };

print join "\n", keys %{ Symbol::stash("main") };

delete_glob("${caller}::foo", "CODE");

DESCRIPTION

This module provides a set of additional functions useful for Perl symbols manipulation.

I.e. delete_glob function allows to delete specific slot of symbol name without deleting others.

IMPORTS

By default, the class does not export its symbols.

use Symbol::Util ':all';

Imports all available symbols.

FUNCTIONS

fetch_glob( name : Str ) : GlobRef

Returns a reference to the glob for the specified symbol name. If the symbol does not already exists it will be created. If the symbol name is unqualified it will be looked up in the calling package. It is safe to use this function with use strict 'refs'.

This function is taken from Kurila, a dialect of Perl.

my $caller = caller;
*{ fetch_glob("${caller}::foo") } = sub { "this is foo" };
stash( name : Str ) : HashRef

Returns a refernce to the stash for the specified name. If the stash does not already exists it will be created. The name of the stash does not include the :: at the end. It is safe to use this function with use strict 'refs'.

This function is taken from Kurila, a dialect of Perl.

print join "\n", keys %{ Symbol::stash("main") };
delete_glob( name : Str, slots : Array[Str] ) : Maybe[GlobRef]

Deletes the specified symbol name if slots are not specified, or deletes the specified slots in symbol name (could be one or more of following strings: SCALAR, ARRAY, HASH, CODE, IO, FORMAT).

Function returns the glob reference if there are any slots defined.

our $FOO = 1;
sub FOO { "bar" };

delete_glob("FOO", "CODE");

print $FOO;  # prints "1"
FOO();       # error: sub not found

SEE ALSO

Symbol.

BUGS

delete_glob always deletes FORMAT slot.

The SCALAR slot is always defined after delete_glob but can contain a reference to undefined value.

If you find the bug, please report it.

AUTHOR

Piotr Roszatycki <dexter@debian.org>

COPYRIGHT

Copyright (C) 2009 by Piotr Roszatycki <dexter@debian.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html