diff -Nru libclass-c3-componentised-perl-1.0009/Changes libclass-c3-componentised-perl-1.001000/Changes --- libclass-c3-componentised-perl-1.0009/Changes 2011-03-20 00:16:59.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/Changes 2011-08-09 03:29:15.000000000 +0000 @@ -1,5 +1,8 @@ Revision history for Class-C3-Componentised +1.001000 08 Aug 2011 + - Add Class::C3::Componentised::ApplyHooks features + 1.0009 20 Mar 2011 - Stop importing Carp functions (and thus polluting the inheritor namespaces) diff -Nru libclass-c3-componentised-perl-1.0009/debian/changelog libclass-c3-componentised-perl-1.001000/debian/changelog --- libclass-c3-componentised-perl-1.0009/debian/changelog 2011-03-20 12:56:10.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/debian/changelog 2011-08-11 12:22:09.000000000 +0000 @@ -1,3 +1,21 @@ +libclass-c3-componentised-perl (1.001000-1) unstable; urgency=low + + * Team upload. + + [ Ansgar Burchardt ] + * New upstream release. + * Add whatis entry for Class::C3::Componentised::ApplyHooks. + + update patch whatis.diff + * debian/copyright: Update years of copyright for inc/Module/*. + * debian/control: Convert Vcs-* fields to Git. + * Bump Standards-Version to 3.9.2 (no changes). + + [ Salvatore Bonaccorso ] + * debian/copyright: Replace DEP5 Format-Specification URL from + svn.debian.org to anonscm.debian.org URL. + + -- Ansgar Burchardt Thu, 11 Aug 2011 14:21:17 +0200 + libclass-c3-componentised-perl (1.0009-1) unstable; urgency=low * New upstream release diff -Nru libclass-c3-componentised-perl-1.0009/debian/control libclass-c3-componentised-perl-1.001000/debian/control --- libclass-c3-componentised-perl-1.0009/debian/control 2011-03-20 12:49:07.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/debian/control 2011-08-11 12:16:04.000000000 +0000 @@ -13,10 +13,10 @@ Uploaders: Krzysztof Krzyżaniak (eloy) , Jonathan Yu , Brian Cassidy , Franck Joncourt -Standards-Version: 3.9.1 +Standards-Version: 3.9.2 Homepage: http://search.cpan.org/dist/Class-C3-Componentised/ -Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libclass-c3-componentised-perl/ -Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libclass-c3-componentised-perl/ +Vcs-Git: git://git.debian.org/pkg-perl/packages/libclass-c3-componentised-perl.git +Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-perl/packages/libclass-c3-componentised-perl.git Package: libclass-c3-componentised-perl Architecture: all diff -Nru libclass-c3-componentised-perl-1.0009/debian/copyright libclass-c3-componentised-perl-1.001000/debian/copyright --- libclass-c3-componentised-perl-1.0009/debian/copyright 2011-03-20 12:56:10.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/debian/copyright 2011-08-11 12:13:59.000000000 +0000 @@ -1,4 +1,4 @@ -Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 +Format-Specification: http://anonscm.debian.org/viewvc/dep/web/deps/dep5.mdwn?view=markup&pathrev=135 Maintainer: DBIx::Class Developers Source: http://search.cpan.org/dist/Class-C3-Componentised/ Name: Class-C3-Componentised @@ -11,9 +11,9 @@ copyright information for the libdbix-class-perl package. Files: inc/Module/* -Copyright: 2002-2010, Adam Kennedy - 2002-2010, Audrey Tang - 2002-2010, Brian Ingerson +Copyright: 2002-2011, Adam Kennedy + 2002-2011, Audrey Tang + 2002-2011, Brian Ingerson License: Artistic or GPL-1+ Files: debian/* diff -Nru libclass-c3-componentised-perl-1.0009/debian/patches/t_upstream_spelling.diff libclass-c3-componentised-perl-1.001000/debian/patches/t_upstream_spelling.diff --- libclass-c3-componentised-perl-1.0009/debian/patches/t_upstream_spelling.diff 2011-03-20 12:49:07.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/debian/patches/t_upstream_spelling.diff 2011-08-11 12:15:44.000000000 +0000 @@ -10,9 +10,9 @@ lib/Class/C3/Componentised.pm | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) ---- a/lib/Class/C3/Componentised.pm -+++ b/lib/Class/C3/Componentised.pm -@@ -236,7 +236,7 @@ +--- libclass-c3-componentised-perl.orig/lib/Class/C3/Componentised.pm ++++ libclass-c3-componentised-perl/lib/Class/C3/Componentised.pm +@@ -250,7 +250,7 @@ Matt S. Trout and the L diff -Nru libclass-c3-componentised-perl-1.0009/debian/patches/whatis.patch libclass-c3-componentised-perl-1.001000/debian/patches/whatis.patch --- libclass-c3-componentised-perl-1.0009/debian/patches/whatis.patch 2010-10-12 11:10:59.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/debian/patches/whatis.patch 2011-08-11 12:21:11.000000000 +0000 @@ -3,8 +3,8 @@ Origin: vendor Forwarded: no ---- a/lib/Class/C3/Componentised.pm -+++ b/lib/Class/C3/Componentised.pm +--- libclass-c3-componentised-perl.orig/lib/Class/C3/Componentised.pm ++++ libclass-c3-componentised-perl/lib/Class/C3/Componentised.pm @@ -2,7 +2,7 @@ =head1 NAME @@ -14,3 +14,14 @@ =head1 DESCRIPTION +--- libclass-c3-componentised-perl.orig/lib/Class/C3/Componentised/ApplyHooks.pm ++++ libclass-c3-componentised-perl/lib/Class/C3/Componentised/ApplyHooks.pm +@@ -90,7 +90,7 @@ + + =head1 NAME + +-Class::C3::Componentised::ApplyHooks ++Class::C3::Componentised::ApplyHooks - allow component to run methods on the class that is being injected into + + =head1 SYNOPSIS + diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install/Base.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install/Base.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install/Base.pm 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install/Base.pm 2011-08-09 03:34:04.000000000 +0000 @@ -4,7 +4,7 @@ use strict 'vars'; use vars qw{$VERSION}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; } # Suspend handler for "redefined" warnings diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install/Can.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install/Can.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install/Can.pm 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install/Can.pm 2011-08-09 03:34:04.000000000 +0000 @@ -9,7 +9,7 @@ use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install/Fetch.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install/Fetch.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install/Fetch.pm 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install/Fetch.pm 2011-08-09 03:34:04.000000000 +0000 @@ -6,7 +6,7 @@ use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install/Makefile.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install/Makefile.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install/Makefile.pm 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install/Makefile.pm 2011-08-09 03:34:04.000000000 +0000 @@ -8,7 +8,7 @@ use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install/Metadata.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install/Metadata.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install/Metadata.pm 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install/Metadata.pm 2011-08-09 03:34:04.000000000 +0000 @@ -6,7 +6,7 @@ use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } @@ -515,6 +515,7 @@ 'GNU Free Documentation license' => 'unrestricted', 1, 'GNU Affero General Public License' => 'open_source', 1, '(?:Free)?BSD license' => 'bsd', 1, + 'Artistic license 2\.0' => 'artistic_2', 1, 'Artistic license' => 'artistic', 1, 'Apache (?:Software )?license' => 'apache', 1, 'GPL' => 'gpl', 1, @@ -550,9 +551,9 @@ sub _extract_bugtracker { my @links = $_[0] =~ m#L<( - \Qhttp://rt.cpan.org/\E[^>]+| - \Qhttp://github.com/\E[\w_]+/[\w_]+/issues| - \Qhttp://code.google.com/p/\E[\w_\-]+/issues/list + https?\Q://rt.cpan.org/\E[^>]+| + https?\Q://github.com/\E[\w_]+/[\w_]+/issues| + https?\Q://code.google.com/p/\E[\w_\-]+/issues/list )>#gx; my %links; @links{@links}=(); diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install/Win32.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install/Win32.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install/Win32.pm 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install/Win32.pm 2011-08-09 03:34:04.000000000 +0000 @@ -6,7 +6,7 @@ use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install/WriteAll.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install/WriteAll.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install/WriteAll.pm 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install/WriteAll.pm 2011-08-09 03:34:04.000000000 +0000 @@ -6,7 +6,7 @@ use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } diff -Nru libclass-c3-componentised-perl-1.0009/inc/Module/Install.pm libclass-c3-componentised-perl-1.001000/inc/Module/Install.pm --- libclass-c3-componentised-perl-1.0009/inc/Module/Install.pm 2011-03-20 00:18:22.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/inc/Module/Install.pm 2011-08-09 03:34:04.000000000 +0000 @@ -31,7 +31,7 @@ # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. - $VERSION = '1.00'; + $VERSION = '1.01'; # Storage for the pseudo-singleton $MAIN = undef; @@ -467,4 +467,4 @@ 1; -# Copyright 2008 - 2010 Adam Kennedy. +# Copyright 2008 - 2011 Adam Kennedy. diff -Nru libclass-c3-componentised-perl-1.0009/lib/Class/C3/Componentised/ApplyHooks.pm libclass-c3-componentised-perl-1.001000/lib/Class/C3/Componentised/ApplyHooks.pm --- libclass-c3-componentised-perl-1.0009/lib/Class/C3/Componentised/ApplyHooks.pm 1970-01-01 00:00:00.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/lib/Class/C3/Componentised/ApplyHooks.pm 2011-08-09 03:22:15.000000000 +0000 @@ -0,0 +1,156 @@ +package Class::C3::Componentised::ApplyHooks; + +use strict; +use warnings; + +our %Before; +our %After; + +sub BEFORE_APPLY (&) { + push @{$Before{scalar caller}}, $_[0]; + $Class::C3::Componentised::APPLICATOR_FOR{scalar caller} = __PACKAGE__; +} +sub AFTER_APPLY (&) { + push @{$After {scalar caller}}, $_[0]; + $Class::C3::Componentised::APPLICATOR_FOR{scalar caller} = __PACKAGE__; +} + +sub _apply_component_to_class { + my ($me, $comp, $target, $apply) = @_; + my @heritage = @{mro::get_linear_isa($comp)}; + + my @before = map { + my $to_run = $Before{$_}; + ($to_run?[$_,$to_run]:()) + } @heritage; + + for my $todo (@before) { + my ($parent, $fn) = @$todo; + for my $f (reverse @$fn) { + $target->$f($parent) + } + } + + $apply->(); + + my @after = map { + my $to_run = $After{$_}; + ($to_run?[$_,$to_run]:()) + } @heritage; + + for my $todo (reverse @after) { + my ($parent, $fn) = @$todo; + for my $f (@$fn) { + $target->$f($parent) + } + } +} + +{ + no strict 'refs'; + sub import { + my ($from, @args) = @_; + my $to = caller; + + my $default = 1; + my $i = 0; + my $skip = 0; + my @import; + for my $arg (@args) { + if ($skip) { + $skip--; + $i++; + next + } + + if ($arg eq '-before_apply') { + $default = 0; + $skip = 1; + push @{$Before{$to}}, $args[$i + 1]; + $Class::C3::Componentised::APPLICATOR_FOR{$to} = $from; + } elsif ($arg eq '-after_apply') { + $default = 0; + $skip = 1; + push @{$After{$to}}, $args[$i + 1]; + $Class::C3::Componentised::APPLICATOR_FOR{$to} = $from; + } elsif ($arg =~ /^BEFORE_APPLY|AFTER_APPLY$/) { + $default = 0; + push @import, $arg + } + $i++; + } + @import = qw(BEFORE_APPLY AFTER_APPLY) + if $default; + + *{"$to\::$_"} = \&{"$from\::$_"} for @import + } +} + +1; + +=head1 NAME + +Class::C3::Componentised::ApplyHooks + +=head1 SYNOPSIS + + package MyComponent; + + our %statistics; + + use Class::C3::Componentised::ApplyHooks + -before_apply => sub { + my ($class, $component) = @_; + + push @{$statistics{$class}}, '-before_apply'; + }, + -after_apply => sub { + my ($class, $component) = @_; + + push @{$statistics{$class}}, '-after_apply'; + }, qw(BEFORE_APPLY AFTER_APPLY); + + BEFORE_APPLY { push @{$statistics{$class}}, 'BEFORE_APPLY' }; + AFTER_APPLY { push @{$statistics{$class}}, 'AFTER_APPLY' }; + AFTER_APPLY { use Devel::Dwarn; Dwarn %statistics }; + + 1; + +=head1 DESCRIPTION + +This package allows a given component to run methods on the class that is being +injected into before or after the component is injected. Note from the +L that all C may be run more than once. + +=head1 IMPORT ACTION + +Both import actions simply run a list of coderefs that will be passed the class +that is being acted upon and the component that is being added to the class. + +=head1 IMPORT OPTIONS + +=head2 -before_apply + +Adds a before apply action for the current component without importing +any subroutines into your namespace. + +=head2 -after_apply + +Adds an after apply action for the current component without importing +any subroutines into your namespace. + +=head1 EXPORTED SUBROUTINES + +=head2 BEFORE_APPLY + + BEFORE_APPLY { warn "about to apply $_[1] to class $_[0]" }; + +Adds a before apply action for the current component. + +=head2 AFTER_APPLY + + AFTER_APPLY { warn "just applied $_[1] to class $_[0]" }; + +Adds an after apply action for the current component. + +=cut diff -Nru libclass-c3-componentised-perl-1.0009/lib/Class/C3/Componentised.pm libclass-c3-componentised-perl-1.001000/lib/Class/C3/Componentised.pm --- libclass-c3-componentised-perl-1.0009/lib/Class/C3/Componentised.pm 2011-03-20 00:16:44.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/lib/Class/C3/Componentised.pm 2011-08-09 03:27:52.000000000 +0000 @@ -48,8 +48,11 @@ use MRO::Compat; use Carp (); +use List::Util (); -our $VERSION = 1.0009; +our $VERSION = '1.001000'; + +$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases my $invalid_class = qr/(?: \b:\b | \:{3,} | \:\:$ )/x; @@ -188,13 +191,24 @@ my $class = shift; my $target = shift; - for (reverse @_) { - no strict 'refs'; - unshift ( @{"${target}::ISA"}, $_ ) - unless ($target eq $_ || $target->isa($_)); - } - mro::set_mro($target, 'c3'); + + for my $comp (reverse @_) { + my $apply = do { + no strict 'refs'; + sub { unshift ( @{"${target}::ISA"}, $comp ) }; + }; + unless ($target eq $comp || $target->isa($comp)) { + our %APPLICATOR_FOR; + if (my $apply_class + = List::Util::first { $APPLICATOR_FOR{$_} } @{mro::get_linear_isa($comp)} + ) { + $APPLICATOR_FOR{$apply_class}->_apply_component_to_class($comp,$target,$apply); + } else { + $apply->(); + } + } + } } =head2 load_optional_class diff -Nru libclass-c3-componentised-perl-1.0009/Makefile.PL libclass-c3-componentised-perl-1.001000/Makefile.PL --- libclass-c3-componentised-perl-1.0009/Makefile.PL 2011-03-20 00:16:07.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/Makefile.PL 2011-08-07 15:29:59.000000000 +0000 @@ -22,4 +22,6 @@ # will need adjustment if the require is removed requires 'Class::C3' => '0.20'; +resources repository => 'git://git.shadowcat.co.uk/p5sagit/Class-C3-Componentised.git'; + WriteAll; diff -Nru libclass-c3-componentised-perl-1.0009/MANIFEST libclass-c3-componentised-perl-1.001000/MANIFEST --- libclass-c3-componentised-perl-1.0009/MANIFEST 2011-03-20 00:18:31.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/MANIFEST 2011-08-09 03:27:58.000000000 +0000 @@ -8,6 +8,7 @@ inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/Class/C3/Componentised.pm +lib/Class/C3/Componentised/ApplyHooks.pm Makefile.PL MANIFEST This list of files META.yml @@ -15,7 +16,9 @@ t/00-load.t t/01-basic.t t/02-explicit.t +t/03-on-apply.t t/03-unstable_dollar_underscore.t +t/04-on-apply-use-base.t t/lib/DestroyDollarUnderscore.pm t/lib/MyModule.pm t/lib/MyModule/ErrorComponent.pm diff -Nru libclass-c3-componentised-perl-1.0009/META.yml libclass-c3-componentised-perl-1.001000/META.yml --- libclass-c3-componentised-perl-1.0009/META.yml 2011-03-20 00:18:24.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/META.yml 2011-08-09 03:34:04.000000000 +0000 @@ -7,7 +7,7 @@ configure_requires: ExtUtils::MakeMaker: 6.42 distribution_type: module -generated_by: 'Module::Install version 1.00' +generated_by: 'Module::Install version 1.01' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -26,4 +26,5 @@ perl: 5.6.2 resources: license: http://dev.perl.org/licenses/ -version: 1.0009 + repository: git://git.shadowcat.co.uk/p5sagit/Class-C3-Componentised.git +version: 1.001000 diff -Nru libclass-c3-componentised-perl-1.0009/t/00-load.t libclass-c3-componentised-perl-1.001000/t/00-load.t --- libclass-c3-componentised-perl-1.0009/t/00-load.t 2010-10-21 07:41:05.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/t/00-load.t 2011-08-09 03:08:43.000000000 +0000 @@ -1,5 +1,3 @@ -#!perl -T - use Test::More tests => 1; BEGIN { diff -Nru libclass-c3-componentised-perl-1.0009/t/03-on-apply.t libclass-c3-componentised-perl-1.001000/t/03-on-apply.t --- libclass-c3-componentised-perl-1.0009/t/03-on-apply.t 1970-01-01 00:00:00.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/t/03-on-apply.t 2011-08-09 03:08:43.000000000 +0000 @@ -0,0 +1,65 @@ +use strict; +use warnings; + +use FindBin; +use Test::More; +use Test::Exception; + +use lib "$FindBin::Bin/lib"; + +my $awesome_robot = 0; +my $first = 0; +my $last = 0; + +BEGIN { + package MyModule::Plugin::TestActions; + + use Class::C3::Componentised::ApplyHooks; + + BEFORE_APPLY { $awesome_robot++; $first = $awesome_robot }; + BEFORE_APPLY { $awesome_robot++; $first = $awesome_robot }; + AFTER_APPLY { $awesome_robot++; $last = $awesome_robot }; + + 1; +} + +BEGIN { + package MyModule::Plugin::TestActionDie; + + use Class::C3::Componentised::ApplyHooks + -before_apply => sub { die 'this component is not applicable (yuk yuk yuk)' }; + + 1; +} + +BEGIN { + package MyModule::Plugin::TestActionLoadFrew; + + use Class::C3::Componentised::ApplyHooks; + + BEFORE_APPLY { $_[0]->load_components('TestActionFrew') }; + + 1; +} + +BEGIN { + package MyModule::Plugin::TestActionFrew; + sub frew { 1 } + 1; +} + +use_ok('MyModule'); +is( $first, 0, 'first starts at zero' ); +is( $last, 0, 'last starts at zero' ); + +MyModule->load_components('TestActions'); +is( $first, 2, 'first gets value of 1 (it runs first)' ); +is( $last, 3, 'last gets value of 2 (it runs last)' ); + +dies_ok { MyModule->load_components('TestActionDie') } 'die from BEFORE_APPLY works'; + +dies_ok { MyModule->frew } 'fREW is not loaded'; +MyModule->load_components('TestActionLoadFrew'); +is( MyModule->frew, 1, 'fREW is loaded' ); + +done_testing; diff -Nru libclass-c3-componentised-perl-1.0009/t/04-on-apply-use-base.t libclass-c3-componentised-perl-1.001000/t/04-on-apply-use-base.t --- libclass-c3-componentised-perl-1.0009/t/04-on-apply-use-base.t 1970-01-01 00:00:00.000000000 +0000 +++ libclass-c3-componentised-perl-1.001000/t/04-on-apply-use-base.t 2011-08-09 03:08:43.000000000 +0000 @@ -0,0 +1,105 @@ +use strict; +use warnings; + +use FindBin; +use Test::More; +use Test::Exception; + +use lib "$FindBin::Bin/lib"; + +BEGIN { + package A::First; + + use Class::C3::Componentised::ApplyHooks; + + AFTER_APPLY { $_[0]->after("a $_[1]") }; + AFTER_APPLY { $_[0]->after("b $_[1]") }; + BEFORE_APPLY { $_[0]->before("a $_[1]") }; + BEFORE_APPLY { $_[0]->before("b $_[1]") }; + + 1; +} + +BEGIN { + package A::Second; + + use base 'A::First'; + + use Class::C3::Componentised::ApplyHooks + -after_apply => sub { $_[0]->after("a $_[1]") }, + -before_apply => sub { $_[0]->before("a $_[1]") }, + qw(BEFORE_APPLY AFTER_APPLY); + + AFTER_APPLY { $_[0]->after("b $_[1]") }; + BEFORE_APPLY { $_[0]->before("b $_[1]") }; + 1; +} + + +BEGIN { + package A::Third; + + use base 'A::Second'; + + 1; +} + +BEGIN { + package A::Class::Second; + + use base 'Class::C3::Componentised'; + use Test::More; + + our @before; + our @after; + + sub component_base_class { 'A' } + __PACKAGE__->load_components('Second'); + + sub before { push @before, $_[1] } + sub after { push @after, $_[1] } + + is_deeply(\@before, [ + 'b A::Second', + 'a A::Second', + 'b A::First', + 'a A::First', + ], 'before runs in the correct order'); + is_deeply(\@after, [ + 'a A::First', + 'b A::First', + 'a A::Second', + 'b A::Second', + ], 'after runs in the correct order'); +} + +BEGIN { + package A::Class::Third; + + use base 'Class::C3::Componentised'; + use Test::More; + + our @before; + our @after; + + sub component_base_class { 'A' } + __PACKAGE__->load_components('Third'); + + sub before { push @before, $_[1] } + sub after { push @after, $_[1] } + + is_deeply(\@before, [ + 'b A::Second', + 'a A::Second', + 'b A::First', + 'a A::First', + ], 'before runs in the correct order'); + is_deeply(\@after, [ + 'a A::First', + 'b A::First', + 'a A::Second', + 'b A::Second', + ], 'after runs in the correct order'); +} + +done_testing;