| 1 | package Role::MethodReturns; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.04'; | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Function::Parameters; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 1 | our @ISA = qw/Exporter/; | |||||||||
| 12 | |||||||||||
| 13 | 1 | our @EXPORT = qw( | |||||||||
| 14 | returns | ||||||||||
| 15 | returns_maybe | ||||||||||
| 16 | returns_self | ||||||||||
| 17 | returns_maybe_self | ||||||||||
| 18 | returns_object_does_interface | ||||||||||
| 19 | returns_maybe_object_does_interface | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | use Import::Into; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | use Type::Params qw/Invocant/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | ▶ | use Types::Standard qw/ClassName Object Maybe/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | ▶ | use Types::Interface qw/ObjectDoesInterface/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub returns { | ||||||||
|
Subroutine
returns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 32 | 0 | my $type_constraint = shift; | |||||||||
| 33 | |||||||||||
| 34 | 0 | $type_constraint->assert_return(@_) | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub returns_maybe { | ||||||||
|
Subroutine
returns_maybe: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 40 | 0 | my $type_constraint = shift; | |||||||||
| 41 | |||||||||||
| 42 | 0 | ( Maybe[$type_constraint] )->assert_return(@_) | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub returns_self { | ||||||||
|
Subroutine
returns_self: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 48 | 0 | my $self = shift; | |||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | return $self if $self eq $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 0 | die "Expected to return '\$self' [$self], got [$_[0]]\n"; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub returns_maybe_self { | ||||||||
|
Subroutine
returns_maybe_self: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 58 | 0 | my $self = shift; | |||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | return unless defined $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | return $self if $self eq $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | 0 | die "Expected to return '\$self' [$self], got [$_[0]]\n"; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub returns_object_does_interface { | ||||||||
|
Subroutine
returns_object_does_interface: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 70 | 0 | my $interface = shift; | |||||||||
| 71 | |||||||||||
| 72 | 0 | ( ObjectDoesInterface[$interface] )->assert_return(@_) | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub returns_maybe_object_does_interface { | ||||||||
|
Subroutine
returns_maybe_object_does_interface: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 78 | 0 | my $interface = shift; | |||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | return unless defined $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | |||||||||||
| 82 | 0 | ( ObjectDoesInterface[$interface] )->assert_return(@_) | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 88 | |||||||||||
| 89 | # TODO: We should only import what we really want to and select | ||||||||||
| 90 | |||||||||||
| 91 | # see Function::Parameters on 'Wrapping Function::Parameters': | ||||||||||
| 92 | # | ||||||||||
| 93 | # Due to its nature as a lexical pragma, importing from Function::Parameters | ||||||||||
| 94 | # always affects the scope that is currently being compiled. If you want to | ||||||||||
| 95 | # write a wrapper module that enables Function::Parameters automatically, | ||||||||||
| 96 | # just call Function::Parameters->import from your own import method (and | ||||||||||
| 97 | # Function::Parameters->unimport from your unimport, as required). | ||||||||||
| 98 | # | ||||||||||
| 99 | 1 | Function::Parameters->import( | |||||||||
| 100 | { | ||||||||||
| 101 | parameters => { | ||||||||||
| 102 | shift => ['$orig', '$self'], | ||||||||||
| 103 | } | ||||||||||
| 104 | }, | ||||||||||
| 105 | { | ||||||||||
| 106 | instance_method => { | ||||||||||
| 107 | shift => ['$original', ['$instance', Object] ], | ||||||||||
| 108 | } | ||||||||||
| 109 | }, | ||||||||||
| 110 | { | ||||||||||
| 111 | class_method => { | ||||||||||
| 112 | shift => ['$original', ['$class', ClassName] ], | ||||||||||
| 113 | } | ||||||||||
| 114 | }, | ||||||||||
| 115 | { | ||||||||||
| 116 | method_parameters => { | ||||||||||
| 117 | shift => ['$original', ['$invocant', Invocant] ], | ||||||||||
| 118 | } | ||||||||||
| 119 | }, | ||||||||||
| 120 | ); | ||||||||||
| 121 | |||||||||||
| 122 | 1 | Role::Tiny->import::into(scalar caller); | |||||||||
| 123 | # | ||||||||||
| 124 | # provides `requires`, `with` | ||||||||||
| 125 | # and the methodmodifiers `around`, `before`, and `after` | ||||||||||
| 126 | |||||||||||
| 127 | 1 | __PACKAGE__->export_to_level( 1, @_ ); | |||||||||
| 128 | # | ||||||||||
| 129 | # whatever is in the list and can be exported, listed in `@EXPORT_OK` | ||||||||||
| 130 | |||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | |||||||||||
| 134 | |||||||||||
| 135 | 1 | 1; | |||||||||
| 136 | |||||||||||