1 package MooseX::Types::Util;
5 MooseX::Types::Util - Common utility functions for the module
16 This package the exportable functions that many parts in
17 L<MooseX::Types> might need.
21 our @EXPORT_OK = qw( filter_tags has_available_type_export );
27 Takes a list and returns two references. The first is a hash reference
28 containing the tags as keys and the number of their appearance as values.
29 The second is an array reference containing all other elements.
43 return \%tags, \@other;
46 =head2 has_available_type_export
48 TypeConstraint | Undef = has_available_type_export($package, $name);
50 This function allows you to introspect if a given type export is available
51 I<at this point in time>. This means that the C<$package> must have imported
52 a typeconstraint with the name C<$name>, and it must be still in its symbol
55 Two arguments are expected:
61 The name of the package to introspect.
65 The name of the type export to introspect.
69 B<Note> that the C<$name> is the I<exported> name of the type, not the declared
70 one. This means that if you use L<Sub::Exporter>s functionality to rename an import
73 use MyTypes Str => { -as => 'MyStr' };
75 you would have to introspect this type like this:
77 has_available_type_export $package, 'MyStr';
79 The return value will be either the type constraint that belongs to the export
80 or an undefined value.
84 sub has_available_type_export {
85 my ($package, $name) = @_;
87 my $sub = $package->can($name)
91 unless $sub->isa('MooseX::Types::EXPORTED_TYPE_CONSTRAINT');
98 L<MooseX::Types::Moose>, L<Exporter>
100 =head1 AUTHOR AND COPYRIGHT
102 Robert 'phaylon' Sedlacek C<E<lt>rs@474.atE<gt>>, with many thanks to
103 the C<#moose> cabal on C<irc.perl.org>.
107 This program is free software; you can redistribute it and/or modify
108 it under the same terms as perl itself.