File Coverage

blib/lib/OOP/Perlish/Class/Abstract/UnitTests/Interfaces.pm
Criterion Covered Total %
statement 90 91 98.9
branch n/a
condition n/a
subroutine 29 30 96.6
pod 0 4 0.0
total 119 125 95.2


line stmt bran cond sub pod time code
1             {
2             package OOP::Perlish::Class::Abstract::UnitTests::MyAbstractClass;
3 1     1   7 use warnings;
  1         2  
  1         38  
4 1     1   5 use strict;
  1         2  
  1         30  
5 1     1   5 use OOP::Perlish::Class::Abstract;
  1         1  
  1         9  
6 1     1   5 use base qw(OOP::Perlish::Class::Abstract);
  1         2  
  1         98  
7              
8             BEGIN {
9 1     1   8 __PACKAGE__->_interfaces(
10             my_interface => 'required',
11             my_optional_interface => 'optional',
12             my_optional_but_true => 'optional_true',
13             );
14             };
15             }
16              
17             {
18             package OOP::Perlish::Class::Abstract::UnitTests::MyImplementationClass;
19 1     1   5 use warnings;
  1         7  
  1         28  
20 1     1   4 use strict;
  1         2  
  1         34  
21 1     1   5 use base qw(OOP::Perlish::Class::Abstract::UnitTests::MyAbstractClass);
  1         1  
  1         702  
22              
23             sub my_interface
24             {
25 1     1   2 my ($self) = @_;
26              
27 1         9 return 'foo';
28             }
29             }
30              
31             {
32             package OOP::Perlish::Class::Abstract::UnitTests::MyBogusImplementationClass;
33 1     1   6 use warnings;
  1         2  
  1         23  
34 1     1   4 use strict;
  1         10  
  1         29  
35 1     1   5 use base qw(OOP::Perlish::Class::Abstract::UnitTests::MyAbstractClass);
  1         2  
  1         619  
36              
37             sub my_optional_interface
38             {
39 0     0   0 return 'foo';
40             }
41             }
42              
43             {
44             package OOP::Perlish::Class::Abstract::UnitTests::MyConsumerClass;
45 1     1   6 use warnings;
  1         1  
  1         22  
46 1     1   5 use strict;
  1         1  
  1         41  
47 1     1   4 use base qw(OOP::Perlish::Class);
  1         2  
  1         91  
48              
49             BEGIN {
50 1     1   14 __PACKAGE__->_accessors(
51             foo => {
52             type => 'OBJECT',
53             implements => [ 'OOP::Perlish::Class::Abstract::UnitTests::MyAbstractClass' ],
54             required => 1,
55             },
56             );
57             };
58              
59             sub quux
60             {
61 1     1   2 my ($self) = @_;
62              
63 1         5 return $self->foo()->my_interface();
64             }
65             }
66              
67             {
68             package OOP::Perlish::Class::Abstract::UnitTests::Interfaces;
69 1     1   8 use warnings;
  1         1  
  1         32  
70 1     1   5 use strict;
  1         1  
  1         68  
71 1     1   6 use base qw(Test::Class);
  1         2  
  1         87  
72 1     1   1275 use Test::More;
  1         7439  
  1         10  
73              
74             sub implementation : Test
75             {
76 1     1 0 1857 my ($self) = @_;
77              
78 1         23 my $foo = OOP::Perlish::Class::Abstract::UnitTests::MyImplementationClass->new();
79 1         15 my $bar = OOP::Perlish::Class::Abstract::UnitTests::MyConsumerClass->new( foo => $foo );
80              
81 1         6 is( $bar->quux(), 'foo', 'we get see foo through all this' ) ;
82 1     1   415 }
  1         3  
  1         9  
83              
84             sub negative_implementation : Test(2)
85             {
86 1     1 0 584 my ($self) = @_;
87              
88 1         6 my $foo = OOP::Perlish::Class->new();
89 1         2 my $bar;
90 1         3 eval {
91 1         9 $bar = OOP::Perlish::Class::Abstract::UnitTests::MyConsumerClass->new( foo => $foo );
92             };
93              
94 1         45 ok( "$@", 'we died trying to set an invalid object' );
95 1         365 ok( "$@" =~ m/Invalid required attribute for foo/, 'died for the right reasons' );
96 1     1   415 }
  1         3  
  1         5  
97              
98             sub missing_required_interface : Test(2)
99             {
100 1     1 0 584 my ($self) = @_;
101              
102 1         10 eval {
103 1         18 my $foo = OOP::Perlish::Class::Abstract::UnitTests::MyBogusImplementationClass->new();
104             };
105              
106 1         452 ok( "$@", 'we die when a class is missing required interfaces' );
107 1         345 ok( "$@" =~ m/Failed to define required interfaces: my_interface/, 'we died for the right reasons' );
108 1     1   281 }
  1         8  
  1         5  
109              
110             sub required_method_die : Test(2)
111             {
112 1     1 0 617 my ($self) = @_;
113              
114 1         4 eval {
115 1         11 OOP::Perlish::Class::Abstract::UnitTests::MyBogusImplementationClass->my_interface();
116             };
117 1         274 ok( "$@", 'we die when a class is missing required interfaces' );
118 1         333 ok( "$@" =~ m/Interface my_interface is required, but was not defined/, 'we died for the right reasons' );
119 1     1   279 }
  1         2  
  1         4  
120             }
121             1;
122             =head1 NAME
123              
124             =head1 VERSION
125              
126             =head1 SYNOPSIS
127              
128             =head1 METHODS
129              
130             =head1 AUTHOR
131              
132             Jamie Beverly, C<< >>
133              
134             =head1 BUGS
135              
136             Please report any bugs or feature requests to C,
137             or through
138             the web interface at
139             L. I will be
140             notified, and then you'll
141             automatically be notified of progress on your bug as I make changes.
142              
143             =head1 SUPPORT
144              
145             You can find documentation for this module with the perldoc command.
146              
147             perldoc OOP::Perlish::Class
148              
149              
150             You can also look for information at:
151              
152             =over 4
153              
154             =item * RT: CPAN's request tracker
155              
156             L
157              
158             =item * AnnoCPAN: Annotated CPAN documentation
159              
160             L
161              
162             =item * CPAN Ratings
163              
164             L
165              
166             =item * Search CPAN
167              
168             L
169              
170             =back
171              
172              
173             =head1 ACKNOWLEDGEMENTS
174              
175             =head1 COPYRIGHT & LICENSE
176              
177             Copyright 2009 Jamie Beverly
178              
179             This program is free software; you can redistribute it and/or modify it
180             under the terms of either: the GNU General Public License as published
181             by the Free Software Foundation; or the Artistic License.
182              
183             See http://dev.perl.org/licenses/ for more information.
184              
185             =cut