line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
package OOP::Perlish::Class::Accessor::UnitTests::Array; |
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
4
|
use OOP::Perlish::Class::Accessor::UnitTests::Base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
9
|
1
|
|
|
1
|
|
4
|
use base 'OOP::Perlish::Class::Accessor::UnitTests::Base'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
10
|
1
|
|
|
1
|
|
4
|
use OOP::Perlish::Class::Accessor; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
3
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
12
|
1
|
|
|
1
|
|
308
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
127
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub setup : Test(setup) |
15
|
|
|
|
|
|
|
{ |
16
|
6
|
|
|
6
|
0
|
4793
|
my ($self) = @_; |
17
|
6
|
|
|
|
|
231
|
$self->{accessor} = OOP::Perlish::Class::Accessor->new( type => 'ARRAY', name => 'test', self => bless( {}, __PACKAGE__ ) ); |
18
|
1
|
|
|
1
|
|
13
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get_value |
21
|
|
|
|
|
|
|
{ |
22
|
9
|
|
|
9
|
0
|
13
|
my ($self) = @_; |
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
|
|
38
|
my @values = $self->{accessor}->value(); |
25
|
9
|
|
|
|
|
35
|
return( @values ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Utility function to test positive/negative assignment for validators |
29
|
|
|
|
|
|
|
# Adds 2 + N to your test count |
30
|
|
|
|
|
|
|
sub use_validator(@) |
31
|
|
|
|
|
|
|
{ |
32
|
4
|
|
|
4
|
0
|
11
|
my ( $self, @values ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
20
|
$self->{accessor}->value(@values); |
35
|
4
|
|
|
|
|
29
|
$self->compare_values_to_array(@values); |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
1748
|
$self->{accessor}->value( 'invalid1', 'invalid2', 'invalid3' ); |
38
|
4
|
|
|
|
|
26
|
my @compare_values = $self->get_value(); |
39
|
4
|
|
|
|
|
25
|
is( scalar @compare_values, 0, 'we pass negative assertion of validation' ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Utility function for testing equality |
43
|
|
|
|
|
|
|
# Adds 1 + N to test count |
44
|
|
|
|
|
|
|
sub compare_values_to_array(@) |
45
|
|
|
|
|
|
|
{ |
46
|
12
|
|
|
12
|
0
|
31
|
my ( $self, @values ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
12
|
|
|
|
|
60
|
my @test_values = $self->get_value(); |
49
|
|
|
|
|
|
|
|
50
|
12
|
|
|
|
|
72
|
is( scalar @test_values, scalar @values, 'we pass positive assertion of validation' ); |
51
|
12
|
|
|
|
|
6829
|
for(my $n=0; $n < scalar @values; $n++) { |
52
|
36
|
|
|
|
|
10828
|
is( $values[$n], $test_values[$n], "possitive assertion that \$test_values[$n] == \$values[$n]" ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub test_type_with_array(@) : Test(5) |
57
|
|
|
|
|
|
|
{ |
58
|
2
|
|
|
2
|
0
|
342
|
my ($self) = @_; |
59
|
2
|
|
|
|
|
7
|
my @values = ( 'foo', 'bar', 'baz', 'bup' ); |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
10
|
$self->{accessor}->value(@values); |
62
|
2
|
|
|
|
|
18
|
$self->compare_values_to_array(@values); |
63
|
1
|
|
|
1
|
|
628
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub test_type_with_arrayref(@) : Test(5) |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
2
|
0
|
372
|
my ($self) = @_; |
68
|
2
|
|
|
|
|
8
|
my @values = ( 'foo', 'bar', 'baz', 'bup'); |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
12
|
$self->{accessor}->value( \@values ); |
71
|
2
|
|
|
|
|
25
|
$self->compare_values_to_array(@values); |
72
|
1
|
|
|
1
|
|
295
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub test_handling_of_references_to_other_types : Test(4) |
75
|
|
|
|
|
|
|
{ |
76
|
2
|
|
|
2
|
0
|
10176
|
my ($self) = @_; |
77
|
2
|
|
|
|
|
11
|
my @values = ( {'foo' => 'bar' } ); |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
15
|
$self->{accessor}->value( @values ); |
80
|
2
|
|
|
|
|
19
|
$self->compare_values_to_array( @values ); |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
897
|
@values = ( \'foo' ); |
83
|
2
|
|
|
|
|
12
|
$self->{accessor}->value( @values ); |
84
|
2
|
|
|
|
|
10
|
$self->compare_values_to_array( @values ); |
85
|
1
|
|
|
1
|
|
322
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub test_setting_array_with_regex_validator(@) : Test(6) |
88
|
|
|
|
|
|
|
{ |
89
|
2
|
|
|
2
|
0
|
384
|
my ($self) = @_; |
90
|
2
|
|
|
|
|
10
|
my @values = ( 'test1', 'test2', 'test3', 'test4' ); |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
21
|
$self->{accessor}->validator(qr/.*test.*/i); |
93
|
2
|
|
|
|
|
26
|
$self->use_validator(@values); |
94
|
1
|
|
|
1
|
|
355
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub test_setting_array_with_sub_validator(@) : Test(6) |
97
|
|
|
|
|
|
|
{ |
98
|
2
|
|
|
2
|
0
|
294
|
my ($self) = @_; |
99
|
2
|
|
|
|
|
9
|
my @values = ( 'test1', 'test2', 'test3', 'test4' ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$self->{accessor}->validator( |
102
|
|
|
|
|
|
|
sub { |
103
|
8
|
|
|
8
|
|
17
|
my ( $self, @values ) = @_; |
104
|
8
|
|
|
|
|
12
|
my @checked = (); |
105
|
8
|
100
|
|
|
|
17
|
for( @values ) { return unless( $_ =~ m/^(.*test.*)$/ ); push(@checked, $1) } |
|
20
|
|
|
|
|
92
|
|
|
16
|
|
|
|
|
40
|
|
106
|
4
|
|
|
|
|
24
|
return @checked; |
107
|
|
|
|
|
|
|
} |
108
|
2
|
|
|
|
|
16
|
); |
109
|
2
|
|
|
|
|
10
|
$self->use_validator(@values); |
110
|
1
|
|
|
1
|
|
399
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub unset_value : Test |
113
|
|
|
|
|
|
|
{ |
114
|
2
|
|
|
2
|
0
|
325
|
my ($self) = @_; |
115
|
|
|
|
|
|
|
|
116
|
2
|
|
|
|
|
13
|
my @test = $self->get_value(); |
117
|
2
|
50
|
|
|
|
13
|
ok( ! @test, 'we get an empty list when nothing has been set' ) || diag( Dumper( [ @test ] ) ); |
118
|
1
|
|
|
1
|
|
312
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
=head1 NAME |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 VERSION |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 METHODS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Jamie Beverly, C<< >> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 BUGS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
136
|
|
|
|
|
|
|
or through |
137
|
|
|
|
|
|
|
the web interface at |
138
|
|
|
|
|
|
|
L. I will be |
139
|
|
|
|
|
|
|
notified, and then you'll |
140
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SUPPORT |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
perldoc OOP::Perlish::Class |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
You can also look for information at: |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over 4 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
L |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * CPAN Ratings |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * Search CPAN |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Copyright 2009 Jamie Beverly |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
179
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
180
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |