SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG
DONATE


YUM REPOSITORY

 
 

MAN page from Fedora 28 perl-MooseX-Declare-0.43-7.fc28.noarch.rpm

MooseX::Declare

Section: User Contributed Perl Documentation (3pm)
Updated: 2015-08-16
Index 

NAME

MooseX::Declare - (DEPRECATED) Declarative syntax for Moose 

VERSION

version 0.43 

SYNOPSIS

    use MooseX::Declare;    class BankAccount {        has 'balance' => ( isa => 'Num', is => 'rw', default => 0 );        method deposit (Num $amount) {            $self->balance( $self->balance + $amount );        }        method withdraw (Num $amount) {            my $current_balance = $self->balance();            ( $current_balance >= $amount )                || confess "Account overdrawn";            $self->balance( $current_balance - $amount );        }    }    class CheckingAccount extends BankAccount {        has 'overdraft_account' => ( isa => 'BankAccount', is => 'rw' );        before withdraw (Num $amount) {            my $overdraft_amount = $amount - $self->balance();            if ( $self->overdraft_account && $overdraft_amount > 0 ) {                $self->overdraft_account->withdraw($overdraft_amount);                $self->deposit($overdraft_amount);            }        }    }
 

DESCRIPTION

This module provides syntactic sugar for Moose, the postmodern object systemfor Perl 5. When used, it sets up the "class" and "role" keywords.

Note: Please see the ``WARNING'' section below! 

KEYWORDS

 

class

    class Foo { ... }    my $anon_class = class { ... };

Declares a new class. The class can be either named or anonymous, depending onwhether or not a classname is given. Within the class definition Moose andMooseX::Method::Signatures are set up automatically in addition to the otherkeywords described in this document. At the end of the definition the classwill be made immutable. namespace::autoclean is injected to clean up Moose andother imports for you.

Because of the way the options are parsed, you cannot have a class named ``is'',``with'' or ``extends''.

It's possible to specify options for classes:

extends
    class Foo extends Bar { ... }

Sets a superclass for the class being declared.

with
    class Foo with Role             { ... }    class Foo with Role1 with Role2 { ... }    class Foo with (Role1, Role2)   { ... }

Applies a role or roles to the class being declared.

is mutable
    class Foo is mutable { ... }

Causes the class not to be made immutable after its definition.

Options can also be provided for anonymous classes using the same syntax:

    my $meta_class = class with Role;
 

role

    role Foo { ... }    my $anon_role = role { ... };

Declares a new role. The role can be either named or anonymous, depending onwhether or not a name is given. Within the role definition Moose::Role andMooseX::Method::Signatures are set up automatically in addition to the otherkeywords described in this document. Again, namespace::autoclean is injected toclean up Moose::Role and other imports for you.

It's possible to specify options for roles:

with
    role Foo with Bar { ... }

Applies a role to the role being declared.

 

before / after / around / override / augment

    before   foo ($x, $y, $z) { ... }    after    bar ($x, $y, $z) { ... }    around   baz ($x, $y, $z) { ... }    override moo ($x, $y, $z) { ... }    augment  kuh ($x, $y, $z) { ... }

Add a method modifier. Those work like documented in Moose, except forthe slightly nicer syntax and the method signatures, which work like documentedin MooseX::Method::Signatures.

For the "around" modifier an additional argument called $orig isautomatically set up as the invocant for the method. 

clean

Sometimes you don't want the automatic cleaning the "class" and "role"keywords provide using namespace::autoclean. In those cases you can specify the"dirty" trait for your class or role:

    use MooseX::Declare;    class Foo is dirty { ... }

This will prevent cleaning of your namespace, except for the keywords importedfrom "Moose" or "Moose::Role". Additionally, a "clean" keyword is provided,which allows you to explicitly clean all functions that were defined prior tocalling "clean". Here's an example:

    use MooseX::Declare;    class Foo is dirty {        sub helper_function { ... }        clean;        method foo ($stuff) { ...; return helper_function($stuff); }    }

With that, the helper function won't be available as a method to a user of yourclass, but you're still able to use it inside your class. 

NOTE ON IMPORTS

When creating a class with MooseX::Declare like:

    use MooseX::Declare;    class Foo { ... }

What actually happens is something like this:

    {        package Foo;        use Moose;        use namespace::autoclean;        ...        __PACKAGE__->meta->make_immutable;    }

So if you declare imports outside the class, the symbols get imported into the"main::" namespace, not the class' namespace. The symbols then cannot be calledfrom within the class:

    use MooseX::Declare;    use Data::Dump qw/dump/;    class Foo {        method dump($value) { return dump($value) } # Data::Dump::dump IS NOT in Foo::        method pp($value)   { $self->dump($value) } # an alias for our dump method    }

To solve this, only import MooseX::Declare outside the class definition(because you have to). Make all other imports inside the class definition.

    use MooseX::Declare;    class Foo {        use Data::Dump qw/dump/;        method dump($value) { return dump($value) } # Data::Dump::dump IS in Foo::        method pp($value)   { $self->dump($value) } # an alias for our dump method    }    Foo->new->dump($some_value);    Foo->new->pp($some_value);

NOTE that the import "Data::Dump::dump()" and the method "Foo::dump()",although having the same name, do not conflict with each other, because theimported "dump" function will be cleaned during compile time, so only themethod remains there at run time. If you want to do more esoteric things withimports, have a look at the "clean" keyword and the "dirty" trait. 

WARNING

Warning: MooseX::Declare is based on Devel::Declare, a giant bag of crackoriginally implemented by mst with the goal of upsetting the perl coredevelopers so much by its very existence that they implemented properkeyword handling in the core.

As of perl5 version 14, this goal has been achieved, and modules suchas Devel::CallParser, Function::Parameters, and Keyword::Simple providemechanisms to mangle perl syntax that don't require hallucinogenicdrugs to interpret the error messages they produce.

If you want to use declarative syntax in new code, please for the loveof kittens get yourself a recent perl and look at Moops instead. 

SEE ALSO

*
Moose
*
Moose::Role
*
MooseX::Method::Signatures
*
namespace::autoclean
*
vim syntax: <http://www.vim.org/scripts/script.php?script_id=2526>
*
emacs syntax: <http://github.com/jrockway/cperl-mode>
*
Geany syntax + notes: <http://www.cattlegrid.info/blog/2009/09/moosex-declare-geany-syntax.html>
*
Devel::CallParser
*
Function::Parameters
*
Keyword::Simple
*
Moops
 

AUTHOR

Florian Ragwitz <raflAATTdebian.org> 

CONTRIBUTORS

*
Karen Etheridge <etherAATTcpan.org>
*
Piers Cawley <pdcawleyAATTbofh.org.uk>
*
Robert 'phaylon' Sedlacek <rsAATT474.at>
*
Ash Berlin <ash_githubAATTfiremirror.com>
*
Nick Perez <nperezAATTcpan.org>
*
Nelo Onyiah <nelo.onyiahAATTgmail.com>
*
Chas. J. Owens IV <chas.owensAATTgmail.com>
*
leedo <leeAATTlaylward.com>
*
Michele Beltrame <arthasAATTcpan.org>
*
Frank Wiegand <fwieAATTcpan.org>
*
David Steinbrunner <dsteinbrunnerAATTpobox.com>
*
Oleg Kostyuk <cub.uanicAATTgmail.com>
*
Dave Rolsky <autarchAATTurth.org>
*
Rafael Kitover <rkitoverAATTio.com>
*
Chris Prather <chrisAATTprather.org>
*
Stevan Little <stevan.littleAATTiinteractive.com>
*
Tomas Doran <bobtfishAATTbobtfish.net>
*
Yanick Champoux <yanickAATTbabyl.dyndns.org>
*
Justin Hunter <justin.d.hunterAATTgmail.com>
 

COPYRIGHT AND LICENSE

This software is copyright (c) 2008 by Florian Ragwitz.

This is free software; you can redistribute it and/or modify it underthe same terms as the Perl 5 programming language system itself.


 

Index

NAME
VERSION
SYNOPSIS
DESCRIPTION
KEYWORDS
class
role
before / after / around / override / augment
clean
NOTE ON IMPORTS
WARNING
SEE ALSO
AUTHOR
CONTRIBUTORS
COPYRIGHT AND LICENSE

This document was created byman2html,using the manual pages.