line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::DeclareX::Keyword::interface; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
package # hide |
5
|
|
|
|
|
|
|
MooseX::DeclareX::Keyword::interface::SupportsTestCases; |
6
|
1
|
|
|
1
|
|
26705
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
|
|
|
|
|
|
$MooseX::DeclareX::Keyword::interface::AUTHORITY = 'cpan:TOBYINK'; |
11
|
|
|
|
|
|
|
$MooseX::DeclareX::Keyword::interface::VERSION = '0.003'; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require MooseX::Declare; |
15
|
|
|
|
|
|
|
require MooseX::Interface; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Moose; |
18
|
|
|
|
|
|
|
with qw( |
19
|
|
|
|
|
|
|
MooseX::Declare::Syntax::MooseSetup |
20
|
|
|
|
|
|
|
MooseX::Declare::Syntax::Extending |
21
|
|
|
|
|
|
|
MooseX::DeclareX::Plugin |
22
|
|
|
|
|
|
|
MooseX::DeclareX::Registry |
23
|
|
|
|
|
|
|
MooseX::DeclareX::Keyword::interface::SupportsTestCases |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
around import_symbols_from => sub { 'MooseX::Interface' }; |
27
|
|
|
|
|
|
|
around imported_moose_symbols => sub { qw( requires excludes extends const ) }; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub preferred_identifier { 'interface' } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
before add_namespace_customizations => sub { |
32
|
|
|
|
|
|
|
my ($self, $ctx) = @_; |
33
|
|
|
|
|
|
|
$_->setup_for($ctx->namespace, provided_by => ref $self) |
34
|
|
|
|
|
|
|
foreach @{ $self->default_inner }; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
"Are you using Java?!" |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
MooseX::DeclareX::Keyword::interface - shiny syntax for MooseX::Interface |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use MooseX::DeclareX |
48
|
|
|
|
|
|
|
keywords => [qw/ class interface /], |
49
|
|
|
|
|
|
|
plugins => [qw/ guard build test_case /]; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
interface BankAccountAPI |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
requires 'deposit'; |
54
|
|
|
|
|
|
|
requires 'withdraw'; |
55
|
|
|
|
|
|
|
requires 'balance'; |
56
|
|
|
|
|
|
|
test_case numeric_balance { |
57
|
|
|
|
|
|
|
Scalar::Util::looks_like_number( $_->balance ) |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
class BankAccount with BankAccountAPI |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
has owner => ( |
64
|
|
|
|
|
|
|
is => 'ro', |
65
|
|
|
|
|
|
|
isa => 'Str', |
66
|
|
|
|
|
|
|
required => 1, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
has balance => ( |
69
|
|
|
|
|
|
|
traits => ['Number'], |
70
|
|
|
|
|
|
|
is => 'rw', |
71
|
|
|
|
|
|
|
isa => 'Num', |
72
|
|
|
|
|
|
|
handles => { |
73
|
|
|
|
|
|
|
deposit => 'add', |
74
|
|
|
|
|
|
|
withdraw => 'sub', |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
build balance { 0 } |
78
|
|
|
|
|
|
|
guard withdraw ($amt) { |
79
|
|
|
|
|
|
|
confess "insufficient funds" unless $self->balance >= $amt |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
interface DDBankAccountAPI extends BankAccountAPI |
84
|
|
|
|
|
|
|
{ |
85
|
|
|
|
|
|
|
requires 'setup_direct_debit'; |
86
|
|
|
|
|
|
|
requires 'pay_direct_debit'; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
BankAccountAPI->meta->test_implementation( BankAccount->new ); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This distribution adds a new keyword and a new plugin to L<MooseX::DeclareX>. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item C<< interface >> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Defines an interface. An interface is much like a role, but with some heavy |
100
|
|
|
|
|
|
|
restrictions - it can't define any methods (just require implementing classes |
101
|
|
|
|
|
|
|
to define them), and it can only extend other interfaces, not roles. See |
102
|
|
|
|
|
|
|
L<MooseX::Interface> for details. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item C<< test_case >> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Sets up test cases for an interface. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=back |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 BUGS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Please report any bugs to |
113
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-DeclareX-Keyword-interface>. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SEE ALSO |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L<MooseX::DeclareX>, L<MooseX::Interface>. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Toby Inkster. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
128
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
134
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
135
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
136
|
|
|
|
|
|
|
|