#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 18; # inheritance tree looks like: # # SuperL SuperR # \ / # MiddleL MiddleR # \ / # -Child- # the Child and MiddleR modules use modifiers # Child will modify a method in SuperL (sl_c) # Child will modify a method in SuperR (sr_c) # Child will modify a method in SuperR already modified by MiddleR (sr_m_c) # SuperL and MiddleR will both have a method of the same name, doing different # things (called 'conflict' and 'cnf_mod') # every method and modifier will just return my $SuperL = SuperL->new(); my $SuperR = SuperR->new(); my $MiddleL = MiddleL->new(); my $MiddleR = MiddleR->new(); my $Child = Child->new(); is($SuperL->superl, "", "SuperL loaded correctly"); is($SuperR->superr, "", "SuperR loaded correctly"); is($MiddleL->middlel, "", "MiddleL loaded correctly"); is($MiddleR->middler, "", "MiddleR loaded correctly"); is($Child->child, "", "Child loaded correctly"); is($SuperL->sl_c, "", "SuperL->sl_c on SuperL"); is($Child->sl_c, ">", "SuperL->sl_c wrapped by Child's around"); is($SuperR->sr_c, "", "SuperR->sr_c on SuperR"); is($Child->sr_c, ">", "SuperR->sr_c wrapped by Child's around"); is($SuperR->sr_m_c, "", "SuperR->sr_m_c on SuperR"); is($MiddleR->sr_m_c, ">", "SuperR->sr_m_c wrapped by MiddleR's around"); is($Child->sr_m_c, ">>", "MiddleR->sr_m_c's wrapping wrapped by Child's around"); is($SuperL->conflict, "", "SuperL->conflict on SuperL"); is($MiddleR->conflict, "", "MiddleR->conflict on MiddleR"); is($Child->conflict, "", "SuperL->conflict on Child"); is($SuperL->cnf_mod, "", "SuperL->cnf_mod on SuperL"); is($MiddleR->cnf_mod, "", "MiddleR->cnf_mod on MiddleR"); is($Child->cnf_mod, ">", "SuperL->cnf_mod wrapped by Child's around"); BEGIN { { package SuperL; sub new { bless {}, shift } sub superl { "" } sub conflict { "" } sub cnf_mod { "" } sub sl_c { "" } } { package SuperR; sub new { bless {}, shift } sub superr { "" } sub sr_c { "" } sub sr_m_c { "" } } { package MiddleL; our @ISA = 'SuperL'; sub middlel { "" } } { package MiddleR; our @ISA = 'SuperR'; use Class::Method::Modifiers; sub middler { "" } sub conflict { "" } sub cnf_mod { "" } around sr_m_c => sub { my $orig = shift; return "(@_).">" }; } { package Child; our @ISA = ('MiddleL', 'MiddleR'); use Class::Method::Modifiers; sub child { "" } around cnf_mod => sub { "(@_).">" }; around sl_c => sub { "(@_).">" }; around sr_c => sub { "(@_).">" }; around sr_m_c => sub { my $orig = shift; return "(@_).">" }; } }