Bumping version to 1.001_001
[p5sagit/Class-C3-Componentised.git] / t / 03-on-apply.t
CommitLineData
e6b8b400 1use strict;
2use warnings;
3
4use FindBin;
5use Test::More;
6use Test::Exception;
7
8use lib "$FindBin::Bin/lib";
9
10my $awesome_robot = 0;
11my $first = 0;
12my $last = 0;
13
14BEGIN {
15 package MyModule::Plugin::TestActions;
16
17 use Class::C3::Componentised::ApplyHooks;
18
19 BEFORE_APPLY { $awesome_robot++; $first = $awesome_robot };
20 BEFORE_APPLY { $awesome_robot++; $first = $awesome_robot };
21 AFTER_APPLY { $awesome_robot++; $last = $awesome_robot };
22
23 1;
24}
25
26BEGIN {
27 package MyModule::Plugin::TestActionDie;
28
29 use Class::C3::Componentised::ApplyHooks
30 -before_apply => sub { die 'this component is not applicable (yuk yuk yuk)' };
31
32 1;
33}
34
35BEGIN {
36 package MyModule::Plugin::TestActionLoadFrew;
37
38 use Class::C3::Componentised::ApplyHooks;
39
40 BEFORE_APPLY { $_[0]->load_components('TestActionFrew') };
41
42 1;
43}
44
45BEGIN {
46 package MyModule::Plugin::TestActionFrew;
47 sub frew { 1 }
48 1;
49}
50
51use_ok('MyModule');
52is( $first, 0, 'first starts at zero' );
53is( $last, 0, 'last starts at zero' );
54
55MyModule->load_components('TestActions');
56is( $first, 2, 'first gets value of 1 (it runs first)' );
57is( $last, 3, 'last gets value of 2 (it runs last)' );
58
59dies_ok { MyModule->load_components('TestActionDie') } 'die from BEFORE_APPLY works';
60
61dies_ok { MyModule->frew } 'fREW is not loaded';
62MyModule->load_components('TestActionLoadFrew');
63is( MyModule->frew, 1, 'fREW is loaded' );
64
65done_testing;