MooseX::Types::LoadableClass - ClassName type constraint with coercion to load the class.
package MyClass; use Moose; use MooseX::Types::LoadableClass qw/ LoadableClass /; has foobar_class => ( is => 'ro', required => 1, isa => LoadableClass, coerce => 1, ); 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::MOP::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.
LoadableClass
Tomas Doran (t0m) <bobtfish@bobtfish.net>
<bobtfish@bobtfish.net>
Florian Ragwitz (rafl) <rafl@debian.org>
<rafl@debian.org>
Copyright (c) 2010 the above named authors.
Licensed under the same terms as perl itself.
To install MooseX::Types::LoadableClass, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Types::LoadableClass
CPAN shell
perl -MCPAN -e shell install MooseX::Types::LoadableClass
For more information on module installation, please visit the detailed CPAN module installation guide.