Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jhthorsen/moosex-barewords
Does magical stuff with barewords in Moose methods
https://github.com/jhthorsen/moosex-barewords
Last synced: 27 days ago
JSON representation
Does magical stuff with barewords in Moose methods
- Host: GitHub
- URL: https://github.com/jhthorsen/moosex-barewords
- Owner: jhthorsen
- Created: 2009-07-08T17:33:45.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2009-08-03T23:19:49.000Z (over 15 years ago)
- Last Synced: 2024-10-16T11:58:42.739Z (3 months ago)
- Language: Perl
- Homepage:
- Size: 89.8 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
NAME
MooseX::Barewords - Turn barewords into attribute/argument gettersDESCRIPTION
The idea is to make $self look like an object and avoid shifting off
arguments given to a method.This module is a proof of concept and will probably never be published
on CPAN.SEE ALSO
MooseX::Method::Signatures, subs::auto, self and selfvars.SYNOPSIS
package Foo;use MooseX::Barewords;
has foo => ( is => 'ro' );
sub my_method {
print self->foo; # this will always return the attribute value
print foo; # will print whatever $self->foo holds
# unless 'foo' is set in argument list
# should that be considered a bug or feature..? ;)
}sub add {
print a + b;
}# this will make 'foo' bareword return 42 instead of
# what $self->foo holds.
$self->my_method(foo => 42);# will print 66
$self->add(a => 42, b => 24);# will die since "a" and "b" are not given as arguments
$self->add(foo => 1);FUNCTIONS
self
$self = self;Returns the current object in caller method.
has
has $name => %args;Same as Moose::has(), but with some extra sugar to make barewords work
as expected.Accessor will be prefixed with "__", but can still be accessed by $name:
$acc = "__$name";
$self->$name eq $self->$acc; # trueinit_meta
$class->init_meta(%options);Called on "import()". Will set up Variable::Magic on caller package and
turn all barewords into subs.INTERNAL FUNCTIONS
get_attr
$value = get_attr($name, @args);Will return either the argument or attribute valued named $name, or
confess if no such arg/attr exists.Arguments will be prioritized over attributes names.
get_arg
$value = get_arg($name, $level);Will return the argument named $name or confess if no such argument
exists in caller method.init_wizard
$wiz = init_wizard();Will return a Variable::Magic wizard, used on caller package.
corelist_map
%corelist = corelist_map();Returns a hash, where the keys are the names of the core functions.
AUTHOR
Jan Henning Thorsen