line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
{ |
2
|
|
|
|
|
|
|
package OOP::Perlish::Class::Accessor::UnitTests::Scalar; |
3
|
1
|
|
|
1
|
|
4
|
use OOP::Perlish::Class::Accessor::UnitTests::Base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use base qw(OOP::Perlish::Class::Accessor::UnitTests::Base); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
76
|
|
5
|
1
|
|
|
1
|
|
4
|
use OOP::Perlish::Class::Accessor; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
4
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
273
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
94
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub setup : Test(setup) |
10
|
|
|
|
|
|
|
{ |
11
|
7
|
|
|
7
|
0
|
7391
|
my ($self) = @_; |
12
|
7
|
|
|
|
|
71
|
$self->{accessor} = OOP::Perlish::Class::Accessor->new( type => 'SCALAR', name => 'test', self => bless({}, __PACKAGE__) ); |
13
|
1
|
|
|
1
|
|
5
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_value |
16
|
|
|
|
|
|
|
{ |
17
|
9
|
|
|
9
|
0
|
16
|
my ($self) = @_; |
18
|
9
|
|
|
|
|
38
|
return $self->{accessor}->value(); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Utility function to test positive/negative assignment for validators |
23
|
|
|
|
|
|
|
sub use_validator(@) { |
24
|
4
|
|
|
4
|
0
|
10
|
my ($self, $value) = @_; |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
17
|
$self->{accessor}->value($value); |
27
|
4
|
|
|
|
|
22
|
is($self->get_value(), $value, 'we pass positive assertion for validation'); |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
10840
|
$self->{accessor}->value('invalid'); |
30
|
4
|
|
|
|
|
20
|
ok( ! $self->get_value(), 'we pass negative assertion for validation'); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub test_negative_assertion_type : Test |
34
|
|
|
|
|
|
|
{ |
35
|
2
|
|
|
2
|
0
|
2242
|
my ($self) = @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
14
|
$self->{accessor}->value('foo' => 'bar'); |
38
|
2
|
|
|
|
|
12
|
ok( ! $self->get_value(), "Cannot set value with invalid type" ); |
39
|
1
|
|
|
1
|
|
334
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub test_negative_assertion_type_ref : Test |
42
|
|
|
|
|
|
|
{ |
43
|
2
|
|
|
2
|
0
|
288
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
11
|
$self->{accessor}->value([ 'foo' ]); |
46
|
2
|
|
|
|
|
12
|
ok( ! $self->get_value(), "Cannot set type with a reference to a non-scalar-type" ); |
47
|
1
|
|
|
1
|
|
194
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub test_type_with_scalar: Test |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
2
|
0
|
388
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
12
|
$self->{accessor}->value('foo'); |
54
|
2
|
|
|
|
|
14
|
is( $self->get_value(), 'foo', 'Value is set with scalar' ); |
55
|
1
|
|
|
1
|
|
211
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub test_type_with_ref : Test |
58
|
|
|
|
|
|
|
{ |
59
|
2
|
|
|
2
|
0
|
324
|
my ($self) = @_; |
60
|
2
|
|
|
|
|
4
|
my $refscalar = 'foo'; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
11
|
$self->{accessor}->value(\$refscalar); |
63
|
2
|
|
|
|
|
12
|
is( $self->get_value(), 'foo', 'value is set with scalar ref'); |
64
|
1
|
|
|
1
|
|
302
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub test_setting_with_regex_validator(@) : Test(2) |
67
|
|
|
|
|
|
|
{ |
68
|
2
|
|
|
2
|
0
|
321
|
my ($self) = @_; |
69
|
2
|
|
|
|
|
19
|
$self->{accessor}->validator( qr/.*test.*/i ); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
16
|
$self->use_validator("test"); |
72
|
1
|
|
|
1
|
|
259
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub test_setting_with_sub_validator(@) : Test(2) |
75
|
|
|
|
|
|
|
{ |
76
|
2
|
|
|
2
|
0
|
448
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
2
|
100
|
|
8
|
|
17
|
$self->{accessor}->validator( sub { my ($self, $value) = @_; $value eq 'hello' && return $value; return } ); |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
43
|
|
|
4
|
|
|
|
|
22
|
|
79
|
2
|
|
|
|
|
11
|
$self->use_validator("hello"); |
80
|
1
|
|
|
1
|
|
250
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub unset_value : Test |
83
|
|
|
|
|
|
|
{ |
84
|
2
|
|
|
2
|
0
|
311
|
my ($self) = @_; |
85
|
2
|
|
|
|
|
11
|
my $undef = $self->get_value(); |
86
|
2
|
50
|
|
|
|
15
|
ok( ! $undef, 'when nothing has been defined, we get undef for scalar' ) || diag(Dumper($undef)); |
87
|
1
|
|
|
1
|
|
277
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 VERSION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Jamie Beverly, C<< >> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 BUGS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
105
|
|
|
|
|
|
|
or through |
106
|
|
|
|
|
|
|
the web interface at |
107
|
|
|
|
|
|
|
L. I will be |
108
|
|
|
|
|
|
|
notified, and then you'll |
109
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SUPPORT |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
perldoc OOP::Perlish::Class |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
You can also look for information at: |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=over 4 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * CPAN Ratings |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * Search CPAN |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Copyright 2009 Jamie Beverly |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
148
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
149
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |