Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

NAME
MooseX::Barewords - Turn barewords into attribute/argument getters

DESCRIPTION
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; # true

init_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