Skip to content

Commit

Permalink
Merge pull request #7 from kfly8/remove_check_phase
Browse files Browse the repository at this point in the history
Remove CHECK phase
  • Loading branch information
kfly8 committed Jun 16, 2019
2 parents 233eb6f + baaf9e2 commit 95555b5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"kfly8 <kfly@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Minilla/v3.1.2, CPAN::Meta::Converter version 2.150010",
"generated_by" : "Minilla/v3.1.4, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
Expand Down Expand Up @@ -42,6 +42,7 @@
},
"runtime" : {
"requires" : {
"B::Hooks::EndOfScope" : "0.23",
"Function::Parameters" : "2.000003",
"Scalar::Util" : "0",
"Scope::Upper" : "0",
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ requires 'Sub::Info';
requires 'Scalar::Util';
requires 'Scope::Upper';
requires 'Function::Parameters', '2.000003';
requires 'B::Hooks::EndOfScope', '0.23';

on 'test' => sub {
requires 'Test::More', '0.98';
Expand Down
18 changes: 6 additions & 12 deletions lib/Function/Return.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use Sub::Util ();
use Sub::Info ();
use Scalar::Util ();
use Scope::Upper ();
use B::Hooks::EndOfScope;
use Function::Parameters;

our $DEFAULT_ATTR_NAME = 'Return';
Expand All @@ -28,6 +29,10 @@ sub import {
no strict qw(refs);
*{"${pkg}::FETCH_CODE_ATTRIBUTES"} = \&_FETCH_CODE_ATTRIBUTES;
*{"${pkg}::MODIFY_CODE_ATTRIBUTES"} = \&_MODIFY_CODE_ATTRIBUTES;

on_scope_end {
_check_sub();
}
}

my %ATTR;
Expand Down Expand Up @@ -170,14 +175,7 @@ sub _register_return_info {
$metadata{$key} = $info;
}

{
no warnings 'void'; # To avoid warnings 'Too late to run CHECK block'
sub CHECK {
check_sub();
}
}

sub check_sub {
sub _check_sub {
for my $decl (@DECLARATIONS) {
my ($pkg, $sub, $types) = @$decl{qw(pkg sub types)};

Expand Down Expand Up @@ -306,10 +304,6 @@ This interface is for power-user. Rather than using the C<< :Return >> attribute
my $wrapped = Function::Return->wrap_sub($orig, [Str]);
$wrapped->();
=head3 Function::Return->check_sub()
Generaly, it's unnecessary to call this method. If you loaded C<Function::Return> at runtime, then you should call C<check_sub> specifically.
=head1 NOTE
=head2 enforce LIST to simplify
Expand Down
13 changes: 13 additions & 0 deletions t/10_case_lazy.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use strict;
use warnings;
use Test::More;
use Test::Fatal;

use lib 't/lib';

# lazy load
require Sample;

like exception { Sample::invalid() }, qr!^Invalid return in fun invalid: return!;

done_testing;
10 changes: 10 additions & 0 deletions t/lib/Sample.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Sample;

use Function::Return;
use Types::Standard -types;

sub invalid :Return(Str) {
return { };
}

1;

0 comments on commit 95555b5

Please sign in to comment.