Changelogging
[gitmo/Mouse.git] / t / 010_basics / 008_wrapped_method_cxt_propagation.t
CommitLineData
60ad2cb7 1#!/usr/bin/perl
fde8e43f 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
60ad2cb7 5
6use strict;
7use warnings;
8
fde8e43f 9use Test::More;
60ad2cb7 10
11
12{
13 package TouchyBase;
14 use Mouse;
15
16 has x => ( is => 'rw', default => 0 );
17
18 sub inc { $_[0]->x( 1 + $_[0]->x ) }
19
20 sub scalar_or_array {
21 wantarray ? (qw/a b c/) : "x";
22 }
23
24 sub void {
25 die "this must be void context" if defined wantarray;
26 }
27
28 package AfterSub;
29 use Mouse;
30
31 extends "TouchyBase";
32
33 after qw/scalar_or_array void/ => sub {
34 my $self = shift;
35 $self->inc;
36 }
37}
38
39my $base = TouchyBase->new;
40my $after = AfterSub->new;
41
42foreach my $obj ( $base, $after ) {
43 my $class = ref $obj;
44 my @array = $obj->scalar_or_array;
45 my $scalar = $obj->scalar_or_array;
46
47 is_deeply(\@array, [qw/a b c/], "array context ($class)");
48 is($scalar, "x", "scalar context ($class)");
49
50 {
51 local $@;
52 eval { $obj->void };
53 ok( !$@, "void context ($class)" );
54 }
55
56 if ( $obj->isa("AfterSub") ) {
57 is( $obj->x, 3, "methods were wrapped" );
58 }
59}
60
fde8e43f 61done_testing;