Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 87366
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: xenoterracide [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: PackageName type
Date: Fri, 26 Jul 2013 17:17:53 -0500
To: bugs-type-tiny [...] rt.cpan.org
From: Caleb Cushing <xenoterracide [...] gmail.com>
I do a lot of things like has _class => ( isa => PackageName, is => 'ro', ); load_class( $self->_class )->new( ... ) could you add PackageName to the standard types? (note: by virtue it does not need to be loaded because it's most often used for later lazy loading, at least for me) here's the MXT module that has it https://metacpan.org/module/MooseX::Types::Perl -- Caleb Cushing http://xenoterracide.com Calendar: https://www.google.com/calendar/embed?src=xenoterracide%40gmail.com&ctz=America/Chicago
Here's an example of how you could define them: package MyTypes; use Type::Library -base, -declare => qw(PackageName LoadableClass); use Type::Utils; use Module::Runtime; use Types::Standard qw( StrMatch ClassName ); declare PackageName, as StrMatch[ qr/^ $Module::Runtime::module_name_rx $/x ]; declare LoadableClass, as ClassName; coerce LoadableClass, from PackageName, q{ Module::Runtime::use_module($_) }; I'm not convinced that these necessarily need to be in Types::Standard.
Subject: Re: [rt.cpan.org #87366] PackageName type
Date: Sun, 28 Jul 2013 04:40:53 -0500
To: bug-Type-Tiny [...] rt.cpan.org
From: Caleb Cushing <xenoterracide [...] gmail.com>
On Sat, Jul 27, 2013 at 3:10 AM, Toby Inkster via RT <bug-Type-Tiny@rt.cpan.org> wrote: Show quoted text
> I'm not convinced that these necessarily need to be in Types::Standard. >
it just seems to fit really well with the with what you already have in ClassName and RoleName (actually not sure why ClassName/RoleName are poking to see if they are loaded, I don't actually want to have this stuff loaded yet just that the name matches an appropriate pattern ). I'm not sure why we'd put PackageName in a different package/dist from RoleName/ClassName (esp seeing how it would make sense for those to rely on it for name validation) (defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s) ? $_[0] : undef; the way you suggest doing it would actually load the module to see if it's a valid module name... which might load it earlier than I want to, e.g. I might have an exception object that has it's excpetion class inverted, but I don't want to load the class itself until I try to instantiate it, I may never instantiate it, because I may never need to throw it. -- Caleb Cushing http://xenoterracide.com Calendar: https://www.google.com/calendar/embed?src=xenoterracide%40gmail.com&ctz=America/Chicago
On 2013-07-28T10:41:07+01:00, XENO wrote: Show quoted text
> actually not sure why ClassName/RoleName > are poking to see if they are loaded
Because that's what the ClassName and RoleName type constraints in Moose do. Except where otherwise noted, Types::Standard's Moose-named type constraints behave the same as the native Moose ones. Show quoted text
> I'm not sure why we'd put PackageName in a different > package/dist from RoleName/ClassName
Because doing it well would probably require a dependency on Module::Runtime, and I'd prefer Type::Tiny to have only core dependencies (and I try to keep even those to a minimum). Show quoted text
> the way you suggest doing it would actually load > the module to see if it's a valid module name...
No, the PackageName type above just checks the value is a string matching the regular expression provided by Module::Runtime. This doesn't load the module. The LoadableClass type on the other hand, is basically an alias for ClassName, but has a coercion from PackageName which loads the module.
Released Types::LoadableClass which has a "ModuleName" type which does more or less the above. https://metacpan.org/release/TOBYINK/Types-LoadableClass-0.002