NAME
Types::LoadableClass - type constraints with coercion to load the class
SYNOPSIS
package MyClass;
use Moose; # or Mouse, or Moo, or whatever
use 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.
DESCRIPTION
A Type::Tiny-based clone of MooseX::Types::LoadableClass.
This is to save yourself having to do this repeatedly...
my $tc = subtype as ClassName;
coerce $tc, from Str, via { Class::Load::load_class($_); $_ };
Despite the abstract for this module, LoadableClass
doesn't actually have a coercion, so no need to use coerce => 1
on the attribute. Rather, the class gets loaded as a side-effect of checking that it's loadable.
Type Constraints
ModuleName
-
A subtype of
Str
(see Types::Standard) representing a string that is a valid Perl package name (according to Module::Runtime). LoadableClass
-
A subtype of
ModuleName
that names a module which is either already loaded (according to Class::Load), or can be loaded (by Class::Load). LoadableRole
-
A subtype of
LoadableClass
that names a module which appears to be a role rather than a class.(Because this type constraint is designed to work with Moose, Mouse, Moo, or none of the above, it can't rely on the features of any particular implementation of roles. Therefore is needs to use a heuristic to detect whether a loaded package represents a role or not. Curently this heuristic is the absence of a method named
new
.)
BUGS
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Types-LoadableClass.
SEE ALSO
Types::Standard, MooseX::Types::LoadableClass, Class::Load, Module::Runtime.
AUTHOR
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>.
Improvements and packaging by Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
This software is copyright (c) 2013 by Dagfinn Ilmari Mannsåker, Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.