| 1 | { | ||||||||||
| 2 | package OOP::Perlish::Class::Accessor::UnitTests::Object; | ||||||||||
| 3 | 1 | ▶ | use OOP::Perlish::Class::Accessor::UnitTests::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use base qw(OOP::Perlish::Class::Accessor::UnitTests::Base); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use OOP::Perlish::Class::Accessor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use IO::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Getopt::Long; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use File::Temp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 13 | ▶ | sub setup : Test(setup) | ||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 12 | { | ||||||||||
| 13 | 13 | my ($self) = @_; | |||||||||
| 14 | 13 | $self->{accessor} = OOP::Perlish::Class::Accessor->new( type => 'OBJECT', name => 'test', self => bless({}, __PACKAGE__) ); | |||||||||
| 15 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | sub set_object : Test | ||||||||
|
Subroutine
set_object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 18 | { | ||||||||||
| 19 | 1 | my ($self) = @_; | |||||||||
| 20 | |||||||||||
| 21 | 1 | my $obj = IO::Handle->new(); | |||||||||
| 22 | |||||||||||
| 23 | 1 | $self->{accessor}->value($obj); | |||||||||
| 24 | 1 | is($self->{accessor}->value(), $obj, 'can set an object'); | |||||||||
| 25 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | sub negative_assertion_set_object : Test | ||||||||
|
Subroutine
negative_assertion_set_object: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 28 | { | ||||||||||
| 29 | 1 | my ($self) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 1 | $self->{accessor}->value('foo'); | |||||||||
| 32 | 1 | ▶ | ok( ! $self->{accessor}->value(), 'Negative assertion: cannot set something that is not an object' ) || diag( $self->{accessor}->value() ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 1 | ▶ | sub polymorphism : Test | ||||||||
|
Subroutine
polymorphism: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | { | ||||||||||
| 37 | 1 | my ($self) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 1 | my $obj = IO::Handle->new(); | |||||||||
| 40 | 1 | $self->{accessor}->object_can(['fileno','fdopen','close']); | |||||||||
| 41 | |||||||||||
| 42 | 1 | $self->{accessor}->value($obj); | |||||||||
| 43 | 1 | is($self->{accessor}->value(), $obj, 'can set an object matching object_can'); | |||||||||
| 44 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | |||||||||||
| 46 | 1 | ▶ | sub negative_assert_polymorphism : Test | ||||||||
|
Subroutine
negative_assert_polymorphism: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 47 | { | ||||||||||
| 48 | 1 | my ($self) = @_; | |||||||||
| 49 | |||||||||||
| 50 | 1 | my $obj = Getopt::Long::Parser->new(); | |||||||||
| 51 | 1 | $self->{accessor}->object_can(['fileno','fdopen','close']); | |||||||||
| 52 | |||||||||||
| 53 | 1 | $self->{accessor}->value($obj); | |||||||||
| 54 | 1 | ok( ! $self->{accessor}->value(), 'Negative assertion: cannot set an object not matching object_can'); | |||||||||
| 55 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub negative_assert_derived : Test | ||||||||
|
Subroutine
negative_assert_derived: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 58 | { | ||||||||||
| 59 | 1 | my ($self) = @_; | |||||||||
| 60 | |||||||||||
| 61 | 1 | my $obj = Getopt::Long::Parser->new(); | |||||||||
| 62 | 1 | $self->{accessor}->object_isa(['IO::Handle']); | |||||||||
| 63 | |||||||||||
| 64 | 1 | $self->{accessor}->value($obj); | |||||||||
| 65 | 1 | ok( ! $self->{accessor}->value(), 'Negative assertion: cannot set an object not matching object_isa'); | |||||||||
| 66 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 67 | |||||||||||
| 68 | 1 | ▶ | sub derived : Test | ||||||||
|
Subroutine
derived: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 69 | { | ||||||||||
| 70 | 1 | my ($self) = @_; | |||||||||
| 71 | |||||||||||
| 72 | 1 | my $obj = File::Temp->new(); | |||||||||
| 73 | 1 | $self->{accessor}->object_isa(['IO::Handle']); | |||||||||
| 74 | |||||||||||
| 75 | 1 | $self->{accessor}->value($obj); | |||||||||
| 76 | 1 | is( $self->{accessor}->value(), $obj, 'can set an object not matching object_isa'); | |||||||||
| 77 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 78 | |||||||||||
| 79 | 1 | ▶ | sub validator : Test | ||||||||
|
Subroutine
validator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 80 | { | ||||||||||
| 81 | 1 | my ($self) = @_; | |||||||||
| 82 | |||||||||||
| 83 | 1 | my $obj = File::Temp->new(); | |||||||||
| 84 | 1 | $self->{accessor}->validator(qr/.*Temp.*/); | |||||||||
| 85 | |||||||||||
| 86 | 1 | $self->{accessor}->value($obj); | |||||||||
| 87 | 1 | is( $self->{accessor}->value(), $obj, 'can set an object matching regexp'); | |||||||||
| 88 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 89 | |||||||||||
| 90 | 1 | ▶ | sub negative_validator : Test | ||||||||
|
Subroutine
negative_validator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 91 | { | ||||||||||
| 92 | 1 | my ($self) = @_; | |||||||||
| 93 | |||||||||||
| 94 | 1 | my $obj = IO::Handle->new(); | |||||||||
| 95 | 1 | $self->{accessor}->validator(qr/.*Temp.*/); | |||||||||
| 96 | |||||||||||
| 97 | 1 | $self->{accessor}->value($obj); | |||||||||
| 98 | 1 | ok( ! $self->{accessor}->value(), 'Negative assert: cannot set an object not matching regexp'); | |||||||||
| 99 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 100 | |||||||||||
| 101 | 1 | ▶ | sub validator_sub : Test | ||||||||
|
Subroutine
validator_sub: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||
| 102 | { | ||||||||||
| 103 | 1 | my ($self) = @_; | |||||||||
| 104 | |||||||||||
| 105 | 1 | my $obj = File::Temp->new(); | |||||||||
| 106 | 0 | ▶ | $self->{accessor}->validator(sub { my ($self, $o) = @_; ref($o) =~ m/File::Temp/ && return $o; return }); | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 107 | |||||||||||
| 108 | 1 | $self->{accessor}->value($obj); | |||||||||
| 109 | 1 | is( $self->{accessor}->value(), $obj, 'can set an object matching sub'); | |||||||||
| 110 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 111 | |||||||||||
| 112 | 1 | ▶ | sub negative_validator_sub : Test | ||||||||
|
Subroutine
negative_validator_sub: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 113 | { | ||||||||||
| 114 | 1 | my ($self) = @_; | |||||||||
| 115 | |||||||||||
| 116 | 1 | my $obj = IO::Handle->new(); | |||||||||
| 117 | 1 | ▶ | $self->{accessor}->validator(sub { my ($self, $o) = @_; ref($o) =~ m/File::Temp/ && return $o; return }); | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||
| 118 | |||||||||||
| 119 | 1 | $self->{accessor}->value($obj); | |||||||||
| 120 | 1 | ok( ! $self->{accessor}->value(), 'Negative assert: cannot set an object not matching sub'); | |||||||||
| 121 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 122 | |||||||||||
| 123 | 1 | ▶ | sub implementation : Test | ||||||||
|
Subroutine
implementation: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 124 | { | ||||||||||
| 125 | 1 | my ($self) = @_; | |||||||||
| 126 | |||||||||||
| 127 | 1 | $self->{accessor}->implements([ 'IO::Handle' ]); | |||||||||
| 128 | |||||||||||
| 129 | 1 | my $obj = IO::Handle->new(); | |||||||||
| 130 | 1 | $self->{accessor}->value($obj); | |||||||||
| 131 | 1 | is($self->{accessor}->value(), $obj, 'can set an object matching implementation'); | |||||||||
| 132 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 133 | |||||||||||
| 134 | 1 | ▶ | sub negative_assert_implementation : Test | ||||||||
|
Subroutine
negative_assert_implementation: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 135 | { | ||||||||||
| 136 | 1 | my ($self) = @_; | |||||||||
| 137 | |||||||||||
| 138 | 1 | $self->{accessor}->implements(['IO::Handle']); | |||||||||
| 139 | |||||||||||
| 140 | 1 | my $obj = Getopt::Long::Parser->new(); | |||||||||
| 141 | 1 | $self->{accessor}->value($obj); | |||||||||
| 142 | 1 | ok( ! $self->{accessor}->value(), 'Negative assertion: cannot set an object not matching implementation'); | |||||||||
| 143 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 144 | |||||||||||
| 145 | 1 | ▶ | sub unset_value : Test | ||||||||
|
Subroutine
unset_value: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 146 | { | ||||||||||
| 147 | 1 | my ($self) = @_; | |||||||||
| 148 | 1 | my $undef = $self->{accessor}->value(); | |||||||||
| 149 | 1 | ▶ | ok( ! $undef, 'when nothing has been defined, we get undef for scalar' ) || diag(Dumper($undef)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 151 | } | ||||||||||
| 152 | 1 | 1; | |||||||||
| 153 | |||||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | =head1 NAME | ||||||||||
| 157 | |||||||||||
| 158 | =head1 VERSION | ||||||||||
| 159 | |||||||||||
| 160 | =head1 SYNOPSIS | ||||||||||
| 161 | |||||||||||
| 162 | =head1 METHODS | ||||||||||
| 163 | |||||||||||
| 164 | =head1 AUTHOR | ||||||||||
| 165 | |||||||||||
| 166 | Jamie Beverly, C<< <jbeverly at cpan.org> >> | ||||||||||
| 167 | |||||||||||
| 168 | =head1 BUGS | ||||||||||
| 169 | |||||||||||
| 170 | Please report any bugs or feature requests to C<bug-foo-bar at rt.cpan.org>, | ||||||||||
| 171 | or through | ||||||||||
| 172 | the web interface at | ||||||||||
| 173 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OOP-Perlish-Class>. I will be | ||||||||||
| 174 | notified, and then you'll | ||||||||||
| 175 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 176 | |||||||||||
| 177 | =head1 SUPPORT | ||||||||||
| 178 | |||||||||||
| 179 | You can find documentation for this module with the perldoc command. | ||||||||||
| 180 | |||||||||||
| 181 | perldoc OOP::Perlish::Class | ||||||||||
| 182 | |||||||||||
| 183 | |||||||||||
| 184 | You can also look for information at: | ||||||||||
| 185 | |||||||||||
| 186 | =over 4 | ||||||||||
| 187 | |||||||||||
| 188 | =item * RT: CPAN's request tracker | ||||||||||
| 189 | |||||||||||
| 190 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=OOP-Perlish-Class> | ||||||||||
| 191 | |||||||||||
| 192 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 193 | |||||||||||
| 194 | L<http://annocpan.org/dist/OOP-Perlish-Class> | ||||||||||
| 195 | |||||||||||
| 196 | =item * CPAN Ratings | ||||||||||
| 197 | |||||||||||
| 198 | L<http://cpanratings.perl.org/d/OOP-Perlish-Class> | ||||||||||
| 199 | |||||||||||
| 200 | =item * Search CPAN | ||||||||||
| 201 | |||||||||||
| 202 | L<http://search.cpan.org/dist/OOP-Perlish-Class/> | ||||||||||
| 203 | |||||||||||
| 204 | =back | ||||||||||
| 205 | |||||||||||
| 206 | |||||||||||
| 207 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 208 | |||||||||||
| 209 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 210 | |||||||||||
| 211 | Copyright 2009 Jamie Beverly | ||||||||||
| 212 | |||||||||||
| 213 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 214 | under the terms of either: the GNU General Public License as published | ||||||||||
| 215 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 216 | |||||||||||
| 217 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 218 | |||||||||||
| 219 | =cut | ||||||||||