line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
{ |
2
|
|
|
|
|
|
|
package OOP::Perlish::Class::Accessor::UnitTests::Ref; |
3
|
1
|
|
|
1
|
|
713
|
use OOP::Perlish::Class::Accessor::UnitTests::Base; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw(OOP::Perlish::Class::Accessor::UnitTests::Base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
92
|
|
5
|
1
|
|
|
1
|
|
5
|
use OOP::Perlish::Class::Accessor; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
6
|
1
|
|
|
1
|
|
5
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub setup : Test(setup) |
9
|
|
|
|
|
|
|
{ |
10
|
3
|
|
|
3
|
0
|
6522
|
my ($self) = @_; |
11
|
3
|
|
|
|
|
41
|
$self->{accessor} = OOP::Perlish::Class::Accessor->new( type => 'REF', name => 'test', self => bless({}, __PACKAGE__) ); |
12
|
1
|
|
|
1
|
|
363
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub get_value |
15
|
|
|
|
|
|
|
{ |
16
|
4
|
|
|
4
|
0
|
9
|
my ($self) = @_; |
17
|
4
|
|
|
|
|
20
|
return $self->{accessor}->value(); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Utility function to test positive/negative assignment for validators |
22
|
|
|
|
|
|
|
sub use_validator(@) { |
23
|
1
|
|
|
1
|
0
|
3
|
my ($self, $value) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
6
|
$self->{accessor}->value($value); |
26
|
1
|
|
|
|
|
6
|
is($self->get_value(), $value, 'we pass positive assertion for validation'); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
673
|
$self->{accessor}->value([ 'invalid' ]); |
29
|
1
|
|
|
|
|
7
|
ok( ! $self->get_value(), 'we pass negative assertion for validation'); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub test_negative_assertion_for_type : Test |
33
|
|
|
|
|
|
|
{ |
34
|
1
|
|
|
1
|
0
|
194
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
7
|
$self->{accessor}->value('foo' => 'bar'); |
37
|
1
|
50
|
|
|
|
7
|
ok( ! $self->get_value(), "We pass negative assertion for type" ) || diag($self->get_value()); |
38
|
1
|
|
|
1
|
|
408
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub test_type : Test |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
|
|
1
|
0
|
163
|
my ($self) = @_; |
43
|
1
|
|
|
|
|
4
|
my $refscalar = [ 'foo' ]; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
7
|
$self->{accessor}->value($refscalar); |
46
|
1
|
|
|
|
|
7
|
is( $self->get_value(), $refscalar, 'Value is set with scalar' ); |
47
|
1
|
|
|
1
|
|
258
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub test_setting_with_sub_validator(@) : Test(2) |
50
|
|
|
|
|
|
|
{ |
51
|
1
|
|
|
1
|
0
|
155
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
208
|
use Data::Dumper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
140
|
|
54
|
1
|
100
|
|
4
|
|
11
|
$self->{accessor}->validator( sub { my ($self, $value) = @_; $value->[0] eq 'hello' && return $value; return } ); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
12
|
|
55
|
1
|
|
|
|
|
7
|
$self->use_validator([ 'hello' ]); |
56
|
1
|
|
|
1
|
|
5
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
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<< >> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 BUGS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
74
|
|
|
|
|
|
|
or through |
75
|
|
|
|
|
|
|
the web interface at |
76
|
|
|
|
|
|
|
L. 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 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * CPAN Ratings |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * Search CPAN |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L |
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 |