| 1 | package MooseX::Types::CheckedUtilExports; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Wrap L<Moose::Util::TypeConstraints> to be safer for L<MooseX::Types> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | our $VERSION = '0.51'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Moose::Util::TypeConstraints (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Moose::Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use Carp 'carp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use Sub::Install; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 17 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | my $StringFoundMsg = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | q{WARNING: String found where Type expected (did you use a => instead of a , ?)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 17 | my @exports = qw/type subtype maybe_type duck_type enum coerce from as/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #pod Prevents errors like: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | #pod subtype Foo => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #pod ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #pod Which should be written as: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #pod subtype Foo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #pod ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | #pod When using L<MooseX::Types>. Exported by that module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #pod Exports checked versions of the following subs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | #pod C<type> C<subtype> C<maybe_type> C<duck_type> C<enum> C<coerce> C<from> C<as> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | #pod While C<class_type> and C<role_type> will also register the type in the library. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #pod From L<Moose::Util::TypeConstraints>. See that module for syntax. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #pod =for Pod::Coverage class_type role_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 17 | for my $export (@exports) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 17 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | Sub::Install::install_sub({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | into => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | as => $export, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 140 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 140 | my $caller = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 140 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 140 | ▶ | carp $StringFoundMsg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
ref $_[0] or $_[0] =~ /\b::\b/ or $caller->get_registered_class_type($_[0]) or $caller->get_registered_role_type($_[0])
ref $_[0] or $_[0] =~ /\b::\b/ or $caller->get_registered_class_type($_[0])
ref $_[0] or $_[0] =~ /\b::\b/
MC/DC75%3/4
ref $_[0] or $_[0] =~ /\b::\b/ or $caller->get_registered_class_type($_[0]) or $caller->get_registered_role_type($_[0])
ref $_[0]
$_[0] =~ /\b::\b/
$caller->get_registered_class_type($_[0])
$caller->get_registered_role_type($_[0])
Truth table80%4/5
A or B or C or D
A= ref $_[0]B= $_[0] =~ /\b::\b/C= $caller->get_registered_class_type($_[0])D= $caller->get_registered_role_type($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | unless ref($_[0]) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $_[0] =~ /\b::\b/ || # qualified type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $caller->get_registered_class_type($_[0]) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $caller->get_registered_role_type($_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 139 | goto &{"Moose::Util::TypeConstraints::$export"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 136 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | Moose::Exporter->setup_import_methods( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 17 | with_caller => [ @exports, 'class_type', 'role_type' ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | sub class_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $caller = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | $caller->register_class_type( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | Moose::Util::TypeConstraints::class_type(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub role_type ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
role_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | my ($caller, $name, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | $caller->register_role_type( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | Moose::Util::TypeConstraints::role_type($name, $opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | #pod =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | #pod L<MooseX::Types> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||