1 package MooseX::Types::Util;
6 MooseX::Types::Util - Common utility functions for the module
12 use Scalar::Util 'blessed';
18 This package the exportable functions that many parts in
19 L<MooseX::Types> might need.
23 our @EXPORT_OK = qw( filter_tags has_available_type_export );
29 Takes a list and returns two references. The first is a hash reference
30 containing the tags as keys and the number of their appearance as values.
31 The second is an array reference containing all other elements.
45 return \%tags, \@other;
48 =head2 has_available_type_export
50 TypeConstraint | Undef = has_available_type_export($package, $name);
52 This function allows you to introspect if a given type export is available
53 I<at this point in time>. This means that the C<$package> must have imported
54 a typeconstraint with the name C<$name>, and it must be still in its symbol
57 Two arguments are expected:
63 The name of the package to introspect.
67 The name of the type export to introspect.
71 B<Note> that the C<$name> is the I<exported> name of the type, not the declared
72 one. This means that if you use L<Sub::Exporter>s functionality to rename an import
75 use MyTypes Str => { -as => 'MyStr' };
77 you would have to introspect this type like this:
79 has_available_type_export $package, 'MyStr';
81 The return value will be either the type constraint that belongs to the export
82 or an undefined value.
86 sub has_available_type_export {
87 my ($package, $name) = @_;
89 my $sub = $package->can($name)
93 unless blessed $sub && $sub->isa('MooseX::Types::EXPORTED_TYPE_CONSTRAINT');
100 L<MooseX::Types::Moose>, L<Exporter>
104 See L<MooseX::Types/AUTHOR>.
108 This program is free software; you can redistribute it and/or modify
109 it under the same terms as perl itself.