line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::MechanicalTurk::Template; |
2
|
4
|
|
|
4
|
|
60606
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
132
|
|
3
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
215
|
|
4
|
4
|
|
|
4
|
|
22
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
339
|
|
5
|
4
|
|
|
4
|
|
1793
|
use Net::Amazon::MechanicalTurk::BaseObject; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
119
|
|
6
|
4
|
|
|
4
|
|
1793
|
use Net::Amazon::MechanicalTurk::ModuleUtil; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
128
|
|
7
|
4
|
|
|
4
|
|
2056
|
use Net::Amazon::MechanicalTurk::IOUtil; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
113
|
|
8
|
4
|
|
|
4
|
|
25
|
use IO::File; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
605
|
|
9
|
4
|
|
|
4
|
|
22
|
use IO::Dir; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
4308
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw{ Net::Amazon::MechanicalTurk::BaseObject }; |
14
|
|
|
|
|
|
|
our %EXTENSION_MAPPINGS; |
15
|
|
|
|
|
|
|
our $DEFAULT_EXTENSIONS_LOADED = 0; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our %DEFAULT_EXTENSIONS = ( |
18
|
|
|
|
|
|
|
"Net::Amazon::MechanicalTurk::Template::ReplacementTemplate" => ['rt', 'question'], |
19
|
|
|
|
|
|
|
"Net::Amazon::MechanicalTurk::Template::PerlTemplate" => ['pl'] |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Net::Amazon::MechanicalTurk::Template->attributes(qw{ |
23
|
|
|
|
|
|
|
templateFile |
24
|
|
|
|
|
|
|
templateSource |
25
|
|
|
|
|
|
|
compiled |
26
|
|
|
|
|
|
|
}); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Class methods |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub toTemplate { |
32
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
33
|
0
|
|
|
|
|
0
|
my $source = shift; |
34
|
0
|
0
|
|
|
|
0
|
if (UNIVERSAL::isa($source, "Net::Amazon::MechanicalTurk::Template")) { |
|
|
0
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
return $source; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif (UNIVERSAL::isa($source, "CODE")) { |
38
|
0
|
|
|
|
|
0
|
require Net::Amazon::MechanicalTurk::Template::SubroutineTemplate; |
39
|
0
|
|
|
|
|
0
|
return Net::Amazon::MechanicalTurk::Template::SubroutineTemplate->new( |
40
|
|
|
|
|
|
|
sub => $source |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
0
|
return $class->compile($source); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub compile { |
49
|
2
|
|
|
2
|
0
|
34
|
my $class = shift; |
50
|
2
|
|
|
|
|
3
|
my $file = shift; |
51
|
2
|
|
|
|
|
11
|
my $module = $class->getModuleForFile($file); |
52
|
2
|
50
|
|
|
|
11
|
if (!defined($module)) { |
53
|
2
|
|
|
|
|
705
|
Carp::croak("Can't find module to handle file $file."); |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
0
|
return $module->new(templateFile => $file, @_); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub getModuleForFile { |
59
|
2
|
|
|
2
|
0
|
6
|
my ($class, $file) = @_; |
60
|
2
|
|
|
|
|
4
|
my $ext = $file; |
61
|
2
|
|
|
|
|
18
|
$ext =~ s/^.*\.//; |
62
|
2
|
|
|
|
|
8
|
$ext = lc($ext); |
63
|
2
|
50
|
|
|
|
12
|
if (!$DEFAULT_EXTENSIONS_LOADED) { |
64
|
2
|
|
|
|
|
16
|
Net::Amazon::MechanicalTurk::Template->addExtensionMappings(%DEFAULT_EXTENSIONS); |
65
|
2
|
|
|
|
|
7
|
$DEFAULT_EXTENSIONS_LOADED = 1; |
66
|
|
|
|
|
|
|
} |
67
|
2
|
|
|
|
|
6
|
return $EXTENSION_MAPPINGS{$ext}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub addExtensionMappings { |
71
|
2
|
|
|
2
|
0
|
5
|
my $class = shift; |
72
|
2
|
50
|
33
|
|
|
19
|
my %params = ($#_ == 0 and UNIVERSAL::isa($_[0], "HASH")) ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
73
|
2
|
|
|
|
|
6
|
my $result = 1; |
74
|
2
|
|
|
|
|
13
|
while (my ($module, $extensions) = each %params) { |
75
|
4
|
50
|
|
|
|
42
|
if (!UNIVERSAL::can($module, "new")) { |
76
|
4
|
50
|
|
|
|
29
|
if (Net::Amazon::MechanicalTurk::ModuleUtil->tryRequire($module)) { |
77
|
4
|
50
|
|
|
|
49
|
if (!UNIVERSAL::can($module, "new")) { |
78
|
4
|
|
|
|
|
8
|
$result = 0; |
79
|
4
|
|
|
|
|
1166
|
Carp::carp("Couldn't find constructor in module $module - $@"); |
80
|
4
|
|
|
|
|
29
|
next; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
0
|
|
|
|
|
0
|
$result = 0; |
85
|
0
|
|
|
|
|
0
|
Carp::carp("Couldn't load module $module - $@."); |
86
|
0
|
|
|
|
|
0
|
next; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
0
|
foreach my $extension (@$extensions) { |
90
|
0
|
|
|
|
|
0
|
$EXTENSION_MAPPINGS{lc($extension)} = $module; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
2
|
|
|
|
|
7
|
return $result; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Instance methods |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub init { |
99
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
100
|
0
|
|
|
|
|
|
$self->setAttributes(@_); |
101
|
0
|
0
|
|
|
|
|
if (defined($self->templateFile)) { |
|
|
0
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$self->compileFile($self->templateFile); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif (defined $self->templateSource) { |
105
|
0
|
|
|
|
|
|
$self->templateFile(""); |
106
|
0
|
|
|
|
|
|
$self->compileSource($self->templateSource); |
107
|
|
|
|
|
|
|
} |
108
|
0
|
0
|
|
|
|
|
if (!$self->compiled) { |
109
|
0
|
|
|
|
|
|
Crap::croak("Couldn't compile template."); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub compileFile { |
114
|
0
|
|
|
0
|
0
|
|
my ($self, $file) = @_; |
115
|
0
|
|
|
|
|
|
my $text = Net::Amazon::MechanicalTurk::IOUtil->readContents($file); |
116
|
0
|
|
|
|
|
|
$self->templateFile($file); |
117
|
0
|
|
|
|
|
|
$self->compileSource($text); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub compileSource { |
121
|
0
|
|
|
0
|
0
|
|
my ($self, $source) = @_; |
122
|
|
|
|
|
|
|
# Subclass should implement |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub execute { |
126
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
127
|
0
|
0
|
0
|
|
|
|
my %params = ($#_ == 0 and UNIVERSAL::isa($_[0], "HASH")) ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $self->merge(\%params); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub merge { |
132
|
0
|
|
|
0
|
0
|
|
my ($self, $params) = @_; |
133
|
|
|
|
|
|
|
# Subclass should implement this |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return 1; |