File Coverage

blib/lib/MooseX/DeclareX/Plugin/abstract.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 31 32 96.8


line stmt bran cond sub pod time code
1             package MooseX::DeclareX::Plugin::abstract;
2              
3             BEGIN {
4 2     2   2684117 $MooseX::DeclareX::Plugin::abstract::AUTHORITY = 'cpan:TOBYINK';
5 2         47 $MooseX::DeclareX::Plugin::abstract::VERSION = '0.005';
6             }
7              
8 2     2   1885 use Moose;
  2         580426  
  2         15  
9             with 'MooseX::DeclareX::Plugin';
10              
11 2     2   17897 use MooseX::Declare ();
  2         2204547  
  2         45  
12 2     2   17 use Moose::Util ();
  2         5  
  2         29  
13 2     2   1765 use MooseX::ABCD ();
  2         6235  
  2         256  
14              
15             sub plugin_setup
16             {
17 3     3 0 99654 my ($class, $kw) = @_;
18              
19 3 100       26 if ($kw->isa('MooseX::DeclareX::Keyword::class'))
20             {
21 2         31 $kw->register_feature(abstract => \&_abstract);
22 2     1   477 $kw->register_feature(concrete => sub { (1) });
  1         146418  
23             }
24             }
25              
26             sub _abstract
27             {
28 2     2   504111 my ($self, $ctx, $package) = @_;
29 2         142 $ctx->add_scope_code_parts('use MooseX::ABCD');
30             }
31              
32             1;
33              
34             __END__
35              
36             =head1 NAME
37              
38             MooseX::DeclareX::Plugin::abstract - shiny syntax for MooseX::ABCD
39              
40             =head1 SYNOPSIS
41              
42             class Shape is abstract {
43             requires 'draw';
44             }
45            
46             class Circle extends Shape {
47             method draw { ... }
48             }
49            
50             class Square extends Shape {
51             # does not implement 'draw'
52             } # dies
53            
54             my $shape = Shape->new; # dies
55             my $circle = Circle->new; # succeeds
56              
57             =head1 DESCRIPTION
58              
59             This distribution adds two new plugins to L<MooseX::DeclareX>.
60              
61             =over
62              
63             =item C<< is abstract >>
64              
65             Declares that a class cannot be instantiated.
66              
67             Also allows the standard Moose C<requires> function to work within
68             classes (it normally only works within roles).
69              
70             When a class requires a method, then subclasses are supposed to provide that
71             method. If the subclass itself is also abstract, then it doesn't need to
72             provide the required methods. (There's also a little cheat: classes which
73             are mutable may extend abstract classes without implementing required methods.
74             You should not do this though.)
75              
76             =item C<< is concrete >>
77              
78             A counterpart to C<< is abstract >>. Currently, this is a no-op, but in
79             future it might enable some checks related to abstract classes.
80              
81             =back
82              
83             =head1 BUGS
84              
85             Please report any bugs to
86             L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-DeclareX-Plugin-abstract>.
87              
88             =head1 SEE ALSO
89              
90             L<MooseX::DeclareX>, L<MooseX::ABCD>.
91              
92             =head1 AUTHOR
93              
94             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
95              
96             =head1 COPYRIGHT AND LICENCE
97              
98             This software is copyright (c) 2012 by Toby Inkster.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =head1 DISCLAIMER OF WARRANTIES
104              
105             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
106             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
107             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
108