blob: 841be55ceebf080afb32c44494214a514e946e7b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 2;
use Test::Exception;
package Foo;
use Moose;
sub foo {
my $self = shift;
my ($arg) = shift;
die 'arg must be positive' if $arg < 0;
return $arg;
}
package Foo::Sub;
use Moose;
use MooseX::Mangle;
extends 'Foo';
guard foo => sub {
my $self = shift;
my ($arg) = @_;
return $arg >= 0;
};
package main;
my $foosub = Foo::Sub->new;
is($foosub->foo(2), 2, 'foo is called if guard succeeds');
lives_and { is($foosub->foo(-2), undef) } 'foo returns undef on guard failure';
|