MooseX::Types::LoadableClass - ClassName type constraint with coercion to load the class.
version 0.016
package MyClass;
use Moose;
use MooseX::Types::LoadableClass qw/ LoadableClass /;
has foobar_class => (
is => 'ro',
required => 1,
isa => LoadableClass,
);
MyClass->new(foobar_class => 'FooBar'); # FooBar.pm is loaded or an
# exception is thrown.
use Moose::Util::TypeConstraints;
my $tc = subtype as ClassName;
coerce $tc, from Str, via { Class::Load::load_class($_); $_ };
I've written those three lines of code quite a lot of times, in quite a lot of places.
Now I don't have to.
A normal class / package.
Like LoadableClass
, except the loaded package must be a Moose::Role.
Bugs may be submitted through the RT bug tracker (or [email protected]).
There is also a mailing list available for users of this distribution, at http://lists.perl.org/list/moose.html.
There is also an irc channel available for users of this distribution, at #moose
on irc.perl.org
.
Tomas Doran <[email protected]>
Karen Etheridge <[email protected]>
Dagfinn Ilmari Mannsåker <[email protected]>
Florian Ragwitz <[email protected]>
Graham Knop <[email protected]>
Gregory Oschwald <[email protected]>
Сергей Романов <[email protected]>
This software is copyright (c) 2010 by Infinity Interactive, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.