Commit | Line | Data |
a909a4df |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
1edfdf1c |
6 | use Test::More tests => 3; |
a909a4df |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Moose'); |
11 | } |
12 | |
13 | ## Augment/Inner |
14 | |
15 | { |
16 | package Document::Page; |
17 | use Moose; |
18 | |
19 | has 'body' => (is => 'rw', isa => 'Str', default => sub {''}); |
20 | |
21 | sub create { |
22 | my $self = shift; |
23 | $self->open_page; |
24 | inner(); |
25 | $self->close_page; |
26 | } |
27 | |
28 | sub append_body { |
29 | my ($self, $appendage) = @_; |
30 | $self->body($self->body . $appendage); |
31 | } |
32 | |
33 | sub open_page { (shift)->append_body('<page>') } |
34 | sub close_page { (shift)->append_body('</page>') } |
35 | |
36 | package Document::PageWithHeadersAndFooters; |
37 | use Moose; |
38 | |
39 | extends 'Document::Page'; |
40 | |
41 | augment 'create' => sub { |
42 | my $self = shift; |
43 | $self->create_header; |
44 | inner(); |
45 | $self->create_footer; |
46 | }; |
47 | |
48 | sub create_header { (shift)->append_body('<header/>') } |
49 | sub create_footer { (shift)->append_body('<footer/>') } |
50 | |
51 | package TPSReport; |
52 | use Moose; |
53 | |
54 | extends 'Document::PageWithHeadersAndFooters'; |
55 | |
56 | augment 'create' => sub { |
57 | my $self = shift; |
58 | $self->create_tps_report; |
59 | }; |
60 | |
61 | sub create_tps_report { |
62 | (shift)->append_body('<report type="tps"/>') |
63 | } |
64 | } |
65 | |
66 | my $tps_report = TPSReport->new; |
67 | isa_ok($tps_report, 'TPSReport'); |
68 | |
69 | is( |
70 | $tps_report->create, |
71 | q{<page><header/><report type="tps"/><footer/></page>}, |
72 | '... got the right TPS report'); |
73 | |
74 | |
75 | |
76 | |