Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fgasper/p5-symbol-get
CPAN’s Symbol::Get
https://github.com/fgasper/p5-symbol-get
Last synced: 18 days ago
JSON representation
CPAN’s Symbol::Get
- Host: GitHub
- URL: https://github.com/fgasper/p5-symbol-get
- Owner: FGasper
- License: mit
- Created: 2016-12-20T03:50:34.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-23T18:54:45.000Z (8 months ago)
- Last Synced: 2024-10-22T07:43:31.928Z (2 months ago)
- Language: Perl
- Size: 35.2 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
# NAME
Symbol::Get - Read Perl’s symbol table programmatically
# SYNOPSIS
package Foo;
our $name = 'haha';
our @list = ( 1, 2, 3 );
our %hash = ( foo => 1, bar => 2 );use constant my_const => 'haha';
use constant my_const_list => qw( a b c );
sub doit { ... }
my $name_sr = Symbol::Get::get('$Foo::name'); # \$name
my $list_ar = Symbol::Get::get('@Foo::list'); # \@list
my $hash_hr = Symbol::Get::get('%Foo::hash'); $ \%hash#Defaults to __PACKAGE__ if none is given:
my $doit_cr = Symbol::Get::get('&doit');#Constants:
my $const_val = Symbol::Get::copy_constant('Foo::my_const');
my @const_list = Symbol::Get::copy_constant('Foo::my_const_list');#The below return the same results since get_names() defaults
#to the current package if none is given.
my @names = Symbol::Get::get_names('Foo'); # keys %Foo::
my @names = Symbol::Get::get_names();# DESCRIPTION
Occasionally I have need to reference a variable programmatically.
This module facilitates that by providing an easy, syntactic-sugar-y,
read-only interface to the symbol table.The SYNOPSIS above should pretty well cover usage.
# ABOUT PERL CONSTANTS
Previous versions of this module endorsed constructions like:
my $const_sr = Symbol::Get::get('Foo::my_const');
my $const_ar = Symbol::Get::get('Foo::my_const_list');… to read constants from the symbol table. This isn’t reliable across
Perl versions, though, so don’t do it; instead, use `copy_constant()`.# SEE ALSO
- [Symbol::Values](https://metacpan.org/pod/Symbol%3A%3AValues)
# LICENSE
This module is licensed under the MIT License.