Skip to content

Csson/p5-MoopsX-UsingMoose

Repository files navigation

NAME

MoopsX::UsingMoose - A Moops that uses Moose

Requires Perl 5.14+ Travis status Distribution kwalitee CPAN Testers result coverage 97.4%

VERSION

Version 0.0103, released 2020-07-29.

SYNOPSIS

use MoopsX::UsingMoose;

class My::Class {

    # A Moose based class

}

STATUS

Do note the inherent issues with using Moops.

DESCRIPTION

This is a thin wrapper around Moops that automatically adds using Moose to role and class statements. It does this by applying the included MoopsX::TraitFor::Parser::UsingMoose Moops::Parser trait.

Rationale

While this on the surface doesn't save any keystrokes it reduces cluttering of role/class statements. Consider the following:

use Moops;

class My::Project::Class
types Types::Standard,
      Types::Path::Tiny,
      Types::MyCustomTypes
 with This::Role
using Moose {

    # A Moose based class

}

That is not very nice.

The first step is to get rid of using Moose:

use MoopsX::UsingMoose;

class My::Project::Class
types Types::Standard,
      Types::Path::Tiny,
      Types::MyCustomTypes
 with This::Role {

    # A Moose based class

}

A minor improvement.

However, create a project specific Moops wrapper:

package My::Project::Moops;
use base 'MoopsX::UsingMoose';

use Types::Standard();
use Types::Path::Tiny();
use Types::MyCustomTypes();

sub import {
    my $class = shift;
    my %opts = @_;

    push @{ $opts{'imports'} ||= [] } => (
        'Types::Standard' => ['-types'],
        'Types::Path::Tiny' => ['-types'],
        'Types::MyCustomTypes' => ['-types'],
    );

    $class->SUPER::import(%opts);
}

And the class statement becomes:

use My::Project::Moops;

class My::Project::Class with This::Role {

    # A Moose based class, still with all the types

}

Happiness ensues.

SEE ALSO

SOURCE

https://github.com/Csson/p5-MoopsX-UsingMoose

HOMEPAGE

https://metacpan.org/release/MoopsX-UsingMoose

AUTHOR

Erik Carlsson info@code301.com

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Erik Carlsson.

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

About

Make Moops use Moose instead of Moo

Resources

License

Stars

Watchers

Forks

Packages

No packages published