| 1 | { | ||||||||||
| 2 | package OOP::Perlish::Class::Accessor::UnitTests::Ref; | ||||||||||
| 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 | |||||||||||
| 8 | 3 | ▶ | sub setup : Test(setup) | ||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 9 | { | ||||||||||
| 10 | 3 | my ($self) = @_; | |||||||||
| 11 | 3 | $self->{accessor} = OOP::Perlish::Class::Accessor->new( type => 'REF', name => 'test', self => bless({}, __PACKAGE__) ); | |||||||||
| 12 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | sub get_value | ||||||||||
| 15 | 4 | ▶ | { | ||||||||
|
Subroutine
get_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 16 | 4 | my ($self) = @_; | |||||||||
| 17 | 4 | return $self->{accessor}->value(); | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | # Utility function to test positive/negative assignment for validators | ||||||||||
| 22 | 1 | ▶ | sub use_validator(@) { | ||||||||
|
Subroutine
use_validator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 23 | 1 | my ($self, $value) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 1 | $self->{accessor}->value($value); | |||||||||
| 26 | 1 | is($self->get_value(), $value, 'we pass positive assertion for validation'); | |||||||||
| 27 | |||||||||||
| 28 | 1 | $self->{accessor}->value([ 'invalid' ]); | |||||||||
| 29 | 1 | ok( ! $self->get_value(), 'we pass negative assertion for validation'); | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 1 | ▶ | sub test_negative_assertion_for_type : Test | ||||||||
|
Subroutine
test_negative_assertion_for_type: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 33 | { | ||||||||||
| 34 | 1 | my ($self) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 1 | $self->{accessor}->value('foo' => 'bar'); | |||||||||
| 37 | 1 | ▶ | ok( ! $self->get_value(), "We pass negative assertion for type" ) || diag($self->get_value()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | sub test_type : Test | ||||||||
|
Subroutine
test_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 41 | { | ||||||||||
| 42 | 1 | my ($self) = @_; | |||||||||
| 43 | 1 | my $refscalar = [ 'foo' ]; | |||||||||
| 44 | |||||||||||
| 45 | 1 | $self->{accessor}->value($refscalar); | |||||||||
| 46 | 1 | is( $self->get_value(), $refscalar, 'Value is set with scalar' ); | |||||||||
| 47 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | sub test_setting_with_sub_validator(@) : Test(2) | ||||||||
|
Subroutine
test_setting_with_sub_validator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 50 | { | ||||||||||
| 51 | 1 | my ($self) = @_; | |||||||||
| 52 | |||||||||||
| 53 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 1 | ▶ | $self->{accessor}->validator( sub { my ($self, $value) = @_; $value->[0] eq 'hello' && return $value; return } ); | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 55 | 1 | $self->use_validator([ 'hello' ]); | |||||||||
| 56 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 57 | } | ||||||||||
| 58 | 1 | 1; | |||||||||
| 59 | =head1 NAME | ||||||||||
| 60 | |||||||||||
| 61 | =head1 VERSION | ||||||||||
| 62 | |||||||||||
| 63 | =head1 SYNOPSIS | ||||||||||
| 64 | |||||||||||
| 65 | =head1 METHODS | ||||||||||
| 66 | |||||||||||
| 67 | =head1 AUTHOR | ||||||||||
| 68 | |||||||||||
| 69 | Jamie Beverly, C<< <jbeverly at cpan.org> >> | ||||||||||
| 70 | |||||||||||
| 71 | =head1 BUGS | ||||||||||
| 72 | |||||||||||
| 73 | Please report any bugs or feature requests to C<bug-foo-bar at rt.cpan.org>, | ||||||||||
| 74 | or through | ||||||||||
| 75 | the web interface at | ||||||||||
| 76 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OOP-Perlish-Class>. I will be | ||||||||||
| 77 | notified, and then you'll | ||||||||||
| 78 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 79 | |||||||||||
| 80 | =head1 SUPPORT | ||||||||||
| 81 | |||||||||||
| 82 | You can find documentation for this module with the perldoc command. | ||||||||||
| 83 | |||||||||||
| 84 | perldoc OOP::Perlish::Class | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | You can also look for information at: | ||||||||||
| 88 | |||||||||||
| 89 | =over 4 | ||||||||||
| 90 | |||||||||||
| 91 | =item * RT: CPAN's request tracker | ||||||||||
| 92 | |||||||||||
| 93 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=OOP-Perlish-Class> | ||||||||||
| 94 | |||||||||||
| 95 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 96 | |||||||||||
| 97 | L<http://annocpan.org/dist/OOP-Perlish-Class> | ||||||||||
| 98 | |||||||||||
| 99 | =item * CPAN Ratings | ||||||||||
| 100 | |||||||||||
| 101 | L<http://cpanratings.perl.org/d/OOP-Perlish-Class> | ||||||||||
| 102 | |||||||||||
| 103 | =item * Search CPAN | ||||||||||
| 104 | |||||||||||
| 105 | L<http://search.cpan.org/dist/OOP-Perlish-Class/> | ||||||||||
| 106 | |||||||||||
| 107 | =back | ||||||||||
| 108 | |||||||||||
| 109 | |||||||||||
| 110 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 111 | |||||||||||
| 112 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 113 | |||||||||||
| 114 | Copyright 2009 Jamie Beverly | ||||||||||
| 115 | |||||||||||
| 116 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 117 | under the terms of either: the GNU General Public License as published | ||||||||||
| 118 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 119 | |||||||||||
| 120 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||