logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

MooseX::Types::LoadableClass - ClassName type constraint with coercion to load the class.

Author

       Tomas Doran <bobtfish@bobtfish.net>

Contributors

       •   Karen Etheridge <ether@cpan.org>

       •   Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

       •   Florian Ragwitz <rafl@debian.org>

       •   Graham Knop <haarg@haarg.org>

       •   Gregory Oschwald <goschwald@maxmind.com>

       •   Сергей Романов <sromanov@cpan.org>

Description

           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.

Name

       MooseX::Types::LoadableClass - ClassName type constraint with coercion to load the class.

Support

       Bugs may be submitted through the RT bug tracker
       <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-LoadableClass> (or
       bug-MooseX-Types-LoadableClass@rt.cpan.org <mailto:bug-MooseX-Types-LoadableClass@rt.cpan.org>).

       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"
       <irc://irc.perl.org/#moose>.

Synopsis

           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.

Types Exported

"LoadableClass"
       A normal class / package.

   "LoadableRole"
       Like "LoadableClass", except the loaded package must be a Moose::Role.

Version

       version 0.016

See Also