line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Class::DBI::Lite::Fixture; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
26784
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
179
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my @destroys = ( ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $_instance; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import |
13
|
|
|
|
|
|
|
{ |
14
|
1
|
|
|
1
|
|
38
|
my ($class, @fixtures) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
50
|
|
|
9
|
$_instance ||= bless { }, $class; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
map { |
19
|
1
|
|
|
|
|
3
|
my $setup = "setup_$_"; |
|
1
|
|
|
|
|
2
|
|
20
|
1
|
|
|
|
|
2
|
my $destroy = "destroy_$_"; |
21
|
1
|
|
|
0
|
|
4
|
push @destroys, sub { $class->$destroy }; |
|
0
|
|
|
|
|
0
|
|
22
|
1
|
|
|
|
|
3
|
$class->$setup |
23
|
|
|
|
|
|
|
} @fixtures; |
24
|
|
|
|
|
|
|
}# end import() |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
DESTROY |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
0
|
|
|
map { eval { $_->() } } @destroys; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
}# end DESTROY() |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1;# return true: |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=pod |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Class::DBI::Lite::Fixture - Test fixtures for easy testing. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 In Your Test Fixture |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
package app::fixtures; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use strict; |
47
|
|
|
|
|
|
|
use warnings 'all'; |
48
|
|
|
|
|
|
|
use base 'Class::DBI::Lite::Fixture'; |
49
|
|
|
|
|
|
|
use app::state; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my @state_info = qw( AL:Alabama AK:Alaska AR:Arkansas ); |
52
|
|
|
|
|
|
|
my @states = ( ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub setup_states { |
55
|
|
|
|
|
|
|
push @states, map { |
56
|
|
|
|
|
|
|
my ($abbr, $name) = split /\:/, $_; |
57
|
|
|
|
|
|
|
app::state->find_or_create( |
58
|
|
|
|
|
|
|
name => $name, |
59
|
|
|
|
|
|
|
abbr => $abbr, |
60
|
|
|
|
|
|
|
) |
61
|
|
|
|
|
|
|
} @state_info; |
62
|
|
|
|
|
|
|
}# end setup_states() |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub destroy_states { |
65
|
|
|
|
|
|
|
map { eval{$_->delete} } @states; |
66
|
|
|
|
|
|
|
}# end destroy_states() |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1;# return true: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 In Your Test File |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use strict; |
73
|
|
|
|
|
|
|
use warnings 'all'; |
74
|
|
|
|
|
|
|
use Test::More 'no_plan'; |
75
|
|
|
|
|
|
|
use lib qw( lib t/lib ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Setup your test fixtures: |
78
|
|
|
|
|
|
|
use app::fixtures 'states'; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
use_ok('app::state'); |
81
|
|
|
|
|
|
|
is( |
82
|
|
|
|
|
|
|
app::state->count_search(abbr => 'AL') => 1 |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# The 'app::state' records are automatically deleted in 'destroy_states'! |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This module provides stubs for the use of "test fixtures" to test your code. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Copyright John Drago . All rights reserved. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 LICENSE |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This software is Free software and may be used and redistributed under the |
98
|
|
|
|
|
|
|
same terms as perl itself. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|