Class/Abstract/UnitTests/Interfaces.pm

filter: Statementstmt 98.9% 96 / 97 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.6% 29 / 30 Podpod 0.0% 0 / 4 totaltotal 95.4% 125 / 131 CC 1 SCAR 0.3
CC
1
Cov
99%
my_optional_interface
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Class/UnitTests/Class.pm ↑ Summary Class/UnitTests/Base.pm »
1 {
2 package OOP::Perlish::Class::Abstract::UnitTests::MyAbstractClass;
3 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use OOP::Perlish::Class::Abstract;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use base qw(OOP::Perlish::Class::Abstract);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 __PACKAGE__->_interfaces(
10 my_interface => 'required',
11 my_optional_interface => 'optional',
12 my_optional_but_true => 'optional_true',
13 );
14 };
15 }
16  
17 {
18 1 package OOP::Perlish::Class::Abstract::UnitTests::MyImplementationClass;
19 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use base qw(OOP::Perlish::Class::Abstract::UnitTests::MyAbstractClass);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 sub my_interface
24 1 ▶ {
Subroutine my_interface: called CC=1 SCAR=0.0
25 1 my ($self) = @_;
26  
27 1 return 'foo';
28 }
29 }
30  
31 {
32 1 package OOP::Perlish::Class::Abstract::UnitTests::MyBogusImplementationClass;
33 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶ use base qw(OOP::Perlish::Class::Abstract::UnitTests::MyAbstractClass);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 sub my_optional_interface
38 0 ▶ {
Subroutine my_optional_interface: not called CC=1 SCAR=6.9
39 0 return 'foo';
40 }
41 }
42  
43 {
44 1 package OOP::Perlish::Class::Abstract::UnitTests::MyConsumerClass;
45 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶ use base qw(OOP::Perlish::Class);
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 1 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 __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 1 ▶ {
Subroutine quux: called CC=1 SCAR=0.0
61 1 my ($self) = @_;
62  
63 1 return $self->foo()->my_interface();
64 }
65 }
66  
67 {
68 1 package OOP::Perlish::Class::Abstract::UnitTests::Interfaces;
69 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 ▶ use base qw(Test::Class);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 1 ▶ use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 1 ▶ sub implementation : Test
Subroutine implementation: called CC=1 SCAR=0.0
Pod undocumented
75 {
76 1 my ($self) = @_;
77  
78 1 my $foo = OOP::Perlish::Class::Abstract::UnitTests::MyImplementationClass->new();
79 1 my $bar = OOP::Perlish::Class::Abstract::UnitTests::MyConsumerClass->new( foo => $foo );
80  
81 1 is( $bar->quux(), 'foo', 'we get see foo through all this' ) ;
82 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 1 ▶ sub negative_implementation : Test(2)
Subroutine negative_implementation: called CC=1 SCAR=0.0
Pod undocumented
85 {
86 1 my ($self) = @_;
87  
88 1 my $foo = OOP::Perlish::Class->new();
89 1 my $bar;
90 1 eval {
91 1 $bar = OOP::Perlish::Class::Abstract::UnitTests::MyConsumerClass->new( foo => $foo );
92 };
93  
94 1 ok( "$@", 'we died trying to set an invalid object' );
95 1 ok( "$@" =~ m/Invalid required attribute for foo/, 'died for the right reasons' );
96 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 1 ▶ sub missing_required_interface : Test(2)
Subroutine missing_required_interface: called CC=1 SCAR=0.0
Pod undocumented
99 {
100 1 my ($self) = @_;
101  
102 1 eval {
103 1 my $foo = OOP::Perlish::Class::Abstract::UnitTests::MyBogusImplementationClass->new();
104 };
105  
106 1 ok( "$@", 'we die when a class is missing required interfaces' );
107 1 ok( "$@" =~ m/Failed to define required interfaces: my_interface/, 'we died for the right reasons' );
108 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 1 ▶ sub required_method_die : Test(2)
Subroutine required_method_die: called CC=1 SCAR=0.0
Pod undocumented
111 {
112 1 my ($self) = @_;
113  
114 1 eval {
115 1 OOP::Perlish::Class::Abstract::UnitTests::MyBogusImplementationClass->my_interface();
116 };
117 1 ok( "$@", 'we die when a class is missing required interfaces' );
118 1 ok( "$@" =~ m/Interface my_interface is required, but was not defined/, 'we died for the right reasons' );
119 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
120 }
121 1 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<< <jbeverly at cpan.org> >>
133  
134 =head1 BUGS
135  
136 Please report any bugs or feature requests to C<bug-foo-bar at rt.cpan.org>,
137 or through
138 the web interface at
139 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OOP-Perlish-Class>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=OOP-Perlish-Class>
157  
158 =item * AnnoCPAN: Annotated CPAN documentation
159  
160 L<http://annocpan.org/dist/OOP-Perlish-Class>
161  
162 =item * CPAN Ratings
163  
164 L<http://cpanratings.perl.org/d/OOP-Perlish-Class>
165  
166 =item * Search CPAN
167  
168 L<http://search.cpan.org/dist/OOP-Perlish-Class/>
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
« Class/UnitTests/Class.pm ↑ Summary Class/UnitTests/Base.pm »