line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Smart::Interface::File; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
896
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
20
|
use base qw(Test::Smart::Interface); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
569
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use File::Spec::Functions; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
8
|
1
|
|
|
1
|
|
5
|
use File::Path; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Test::Smart::Question; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
563
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Test::Smart::Interface::File - File based human interface layer for Test::Smart |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Test::Smart; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
initialize('Test::Smart::Interface::File',directory => '/home/tester'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Test::Smart normally from here |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub load { |
29
|
3
|
|
|
3
|
1
|
1218
|
my $class = shift; |
30
|
3
|
|
|
|
|
6
|
my %args = @_; |
31
|
3
|
|
|
|
|
4
|
my $self = {}; |
32
|
3
|
|
|
|
|
5
|
$self->{_nextid} = 0; |
33
|
3
|
|
50
|
|
|
15
|
$self->{_dir} = $args{dir} ||= $args{directory} ||= '.'; |
|
|
|
66
|
|
|
|
|
34
|
3
|
|
|
|
|
6
|
$self->{_questions} = []; |
35
|
|
|
|
|
|
|
|
36
|
3
|
100
|
|
|
|
51
|
unless( -e $self->{_dir}) { |
37
|
1
|
|
|
|
|
3
|
$self->{_dircreat} = 1; |
38
|
1
|
50
|
|
|
|
251
|
mkpath($self->{_dir}) or return undef; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
16
|
bless $self,$class; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub submit { |
45
|
1
|
|
|
1
|
1
|
6
|
my ($self,$question,$name) = @_; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
10
|
my $Qobj = Test::Smart::Question->new( |
48
|
|
|
|
|
|
|
question =>$question, |
49
|
|
|
|
|
|
|
name =>$name, |
50
|
|
|
|
|
|
|
id =>$self->{_nextid}); |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
3
|
push @{$self->{_questions}},$self->{_nextid}; |
|
1
|
|
|
|
|
2
|
|
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
2
|
$self->{_nextid}++; |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
0
|
|
|
8
|
open my $qfile, '>', $self->_get_filename($Qobj->id ,"q") or |
57
|
|
|
|
|
|
|
$self->err("Could not open question file: $!") and return undef; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
15
|
print $qfile <
|
60
|
|
|
|
|
|
|
$name |
61
|
|
|
|
|
|
|
--------- |
62
|
|
|
|
|
|
|
$question |
63
|
|
|
|
|
|
|
QUESTION |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
47
|
close $qfile; |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
5
|
return $Qobj; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub has_answer { |
71
|
9
|
|
|
9
|
1
|
682
|
my ($self,$Qobj) = @_; |
72
|
|
|
|
|
|
|
|
73
|
9
|
|
|
|
|
15
|
my @names = map { $self->_get_filename($Qobj->id,$_) } qw(y n s); |
|
27
|
|
|
|
|
61
|
|
74
|
|
|
|
|
|
|
|
75
|
9
|
|
|
|
|
16
|
foreach (@names) { |
76
|
20
|
100
|
|
|
|
240
|
return 1 if -e $_; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
552
|
return 0; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub answer { |
83
|
5
|
|
|
5
|
1
|
406
|
my ($self,$Qobj) = @_; |
84
|
|
|
|
|
|
|
|
85
|
5
|
100
|
50
|
|
|
9
|
$self->err('Question does not have an answer yet') and return undef unless $self->has_answer($Qobj); |
86
|
4
|
|
|
|
|
11
|
my $id = $Qobj->id; |
87
|
|
|
|
|
|
|
|
88
|
4
|
100
|
|
|
|
12
|
$Qobj->answer('yes',scalar $self->_getcomments($id,'y')), return 1 if $self->_is_y($id); |
89
|
3
|
100
|
|
|
|
9
|
$Qobj->answer('no',scalar $self->_getcomments($id,'n')), return 1 if $self->_is_n($id); |
90
|
1
|
50
|
|
|
|
4
|
$Qobj->skip(scalar $self->_getcomments($id,'s')), return 1 if $self->_is_s($id); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
return undef; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _get_filename { |
96
|
49
|
|
|
49
|
|
70
|
my ($self,$id,$suffix) = @_; |
97
|
|
|
|
|
|
|
|
98
|
49
|
|
|
|
|
1118
|
return catfile($self->{_dir},"question-$id.$suffix"); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _getcomments { |
102
|
4
|
|
|
4
|
|
6
|
my ($self,$id,$suffix) = @_; |
103
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
17
|
open my $commentfile,'<',$self->_get_filename($id,$suffix); |
105
|
4
|
|
|
|
|
66
|
my @commentlines = <$commentfile>; |
106
|
4
|
|
|
|
|
34
|
close $commentfile; |
107
|
|
|
|
|
|
|
|
108
|
4
|
50
|
|
|
|
35
|
return wantarray ? @commentlines : join '',@commentlines; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
foreach my $suffix (qw(y n s)){ |
112
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
197
|
|
113
|
|
|
|
|
|
|
*{__PACKAGE__."::_is_$suffix"} = sub { |
114
|
8
|
|
|
8
|
|
10
|
my ($self,$id) = @_; |
115
|
8
|
|
|
|
|
13
|
return -e $self->_get_filename($id,$suffix); |
116
|
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub DESTROY { |
120
|
3
|
|
|
3
|
|
14
|
my $self = shift; |
121
|
|
|
|
|
|
|
|
122
|
3
|
|
|
|
|
5
|
foreach my $qid (@{$self->{_questions}}) { |
|
3
|
|
|
|
|
732
|
|
123
|
1
|
|
|
|
|
5
|
unlink glob catfile $self->_get_filename($qid,"*"); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
3
|
100
|
|
|
|
195
|
rmdir $self->{_dir} if $self->{_dircreat}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Edgar A. Bering, Etrizor@gmail.comE |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright (C) 2007 by Edgar A. Bering |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
138
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
139
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |