Subject: | methods with 'return' values fail when called in void context. |
As demonstrated in attached text, MXD.pl , when you call a method in any context other than void, it works fine. However, when you call the same method with a defined return type in void context, it fails validation.
My diagnosis of this concludes it appears to be Context::Preserves fault, but it can't be helped. ( See CP.pl for respective demonstration ).
MX::MS validates return types by using Context::Preserve to do so, and hooking into => after(), however, the problem with this is context_preserve, in void context, is trying to maintain that void context, so it can't call the actual method in void context *and* still get any values that are returned anyway, despite being in void context.
My diagnosis of this concludes it appears to be Context::Preserves fault, but it can't be helped. ( See CP.pl for respective demonstration ).
MX::MS validates return types by using Context::Preserve to do so, and hooking into => after(), however, the problem with this is context_preserve, in void context, is trying to maintain that void context, so it can't call the actual method in void context *and* still get any values that are returned anyway, despite being in void context.
Subject: | CP.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Context::Preserve;
use Data::Dumper qw(Dumper);
sub preserved {
return preserve_context { return 1 }
after => sub {
print Dumper( \@_ );
};
}
1;
preserved();
1;
scalar preserved();
1;
my ( @list ) = preserved();
1;
__END__
$VAR1 = [];
$VAR1 = [
1
];
$VAR1 = [
1
];
Subject: | MXD.pl |
#!/usr/bin/perl
use strict;
use warnings;
use MooseX::Declare;
use Test::More 0.96;
use Test::Fatal;
class Tester {
method bar returns (Bool) {
return 1;
}
}
my $tester = Tester->new();
is( exception { $tester->bar(); 1 }, undef, "I Expected this to work despite the fact I don't need its return value.");
is( exception { scalar $tester->bar(); 1 }, undef, "I however seem to need this");
is( exception { my ( @foo ) = $tester->bar(); 1 }, undef, "This also works, its just void context that breaks :( " );
done_testing;