1 package MooseX::Types::Util;
3 #ABSTRACT: Common utility functions for the distribution
7 use Scalar::Util 'blessed';
13 This package the exportable functions that many parts in
14 L<MooseX::Types> might need.
18 our @EXPORT_OK = qw( filter_tags has_available_type_export );
24 Takes a list and returns two references. The first is a hash reference
25 containing the tags as keys and the number of their appearance as values.
26 The second is an array reference containing all other elements.
40 return \%tags, \@other;
43 =head2 has_available_type_export
45 TypeConstraint | Undef = has_available_type_export($package, $name);
47 This function allows you to introspect if a given type export is available
48 I<at this point in time>. This means that the C<$package> must have imported
49 a typeconstraint with the name C<$name>, and it must be still in its symbol
52 Two arguments are expected:
58 The name of the package to introspect.
62 The name of the type export to introspect.
66 B<Note> that the C<$name> is the I<exported> name of the type, not the declared
67 one. This means that if you use L<Sub::Exporter>s functionality to rename an import
70 use MyTypes Str => { -as => 'MyStr' };
72 you would have to introspect this type like this:
74 has_available_type_export $package, 'MyStr';
76 The return value will be either the type constraint that belongs to the export
77 or an undefined value.
81 sub has_available_type_export {
82 my ($package, $name) = @_;
84 my $sub = $package->can($name)
88 unless blessed $sub && $sub->isa('MooseX::Types::EXPORTED_TYPE_CONSTRAINT');
95 L<MooseX::Types::Moose>, L<Exporter>
99 This program is free software; you can redistribute it and/or modify
100 it under the same terms as perl itself.