summaryrefslogtreecommitdiffstats
path: root/t/011-mangle-return.t
diff options
context:
space:
mode:
Diffstat (limited to 't/011-mangle-return.t')
-rw-r--r--t/011-mangle-return.t44
1 files changed, 44 insertions, 0 deletions
diff --git a/t/011-mangle-return.t b/t/011-mangle-return.t
new file mode 100644
index 0000000..0db182b
--- /dev/null
+++ b/t/011-mangle-return.t
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+package Foo;
+use Moose;
+
+sub foo {
+ shift;
+ my @ret = reverse @_;
+ return @ret;
+}
+
+sub bar {
+ shift;
+ return join '-', @_
+}
+
+package Foo::Sub;
+use Moose;
+use MooseX::Mangle;
+extends 'Foo';
+
+mangle_return foo => sub {
+ my $self = shift;
+ return wantarray ? (@_, 'd') : shift() - 1;
+};
+
+mangle_return bar => sub {
+ my $self = shift;
+ my ($ret) = @_;
+ $ret =~ s/-/:/g;
+ return $ret;
+};
+
+package main;
+my $foo = Foo->new;
+my $foosub = Foo::Sub->new;
+is_deeply([$foo->foo(qw(a b c))], [qw(c b a)], 'unmodified method foo');
+is($foo->bar(qw(a b c)), 'a-b-c', 'unmodified method bar');
+is_deeply([$foosub->foo(qw(a b c))], [qw(c b a d)], "foo's args are mangled (list context)");
+is(scalar $foosub->foo(qw(a b c)), 2, "foo's args are mangled (scalar context)");
+is($foosub->bar(qw(a b c)), 'a:b:c', "bar's args are mangled");