line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Poet::Test::Class; |
2
|
|
|
|
|
|
|
$Poet::Test::Class::VERSION = '0.16'; |
3
|
6
|
|
|
6
|
|
322509
|
use Method::Signatures::Simple; |
|
6
|
|
|
|
|
104465
|
|
|
6
|
|
|
|
|
44
|
|
4
|
6
|
|
|
6
|
|
2863
|
use Carp; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
304
|
|
5
|
6
|
|
|
6
|
|
25
|
use Cwd qw(realpath); |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
241
|
|
6
|
6
|
|
|
6
|
|
3188
|
use Plack::Util; |
|
6
|
|
|
|
|
50645
|
|
|
6
|
|
|
|
|
185
|
|
7
|
6
|
|
|
6
|
|
2806
|
use Poet::Environment::Generator; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Poet::Environment; |
9
|
|
|
|
|
|
|
use Poet::Mechanize; |
10
|
|
|
|
|
|
|
use Poet::Tools qw(basename dirname mkpath rmtree tempdir_simple write_file); |
11
|
|
|
|
|
|
|
use Test::Class::Most; |
12
|
|
|
|
|
|
|
use YAML::XS; |
13
|
|
|
|
|
|
|
use strict; |
14
|
|
|
|
|
|
|
use warnings; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->SKIP_CLASS("abstract base class"); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
method write_conf_file ($class:) { |
19
|
|
|
|
|
|
|
my ( $conf_file, $conf_content ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
if ( ref($conf_content) eq 'HASH' ) { |
22
|
|
|
|
|
|
|
$conf_content = %$conf_content ? YAML::XS::Dump($conf_content) : ""; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
mkpath( dirname($conf_file), 0, 0775 ); |
25
|
|
|
|
|
|
|
write_file( $conf_file, $conf_content ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
method temp_env ($class:) { |
29
|
|
|
|
|
|
|
my (%params) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $root_dir = $class->temp_env_dir(%params); |
32
|
|
|
|
|
|
|
my $app_name = $params{app_name} || 'TestApp'; |
33
|
|
|
|
|
|
|
if ( my $conf = $params{conf} ) { |
34
|
|
|
|
|
|
|
$class->write_conf_file( "$root_dir/conf/local.cfg", $conf ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
if ( my $conf_files = $params{conf_files} ) { |
37
|
|
|
|
|
|
|
while ( my ( $conf_file, $contents ) = each(%$conf_files) ) { |
38
|
|
|
|
|
|
|
$class->write_conf_file( "$root_dir/conf/$conf_file", $contents ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
return Poet::Environment->new( |
42
|
|
|
|
|
|
|
root_dir => $root_dir, |
43
|
|
|
|
|
|
|
app_name => $app_name |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
method temp_env_dir ($class:) { |
48
|
|
|
|
|
|
|
my (%params) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
local $ENV{POET_SHARE_DIR} = $params{share_dir} || $class->share_dir; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $app_name = $params{app_name} || 'TestApp'; |
53
|
|
|
|
|
|
|
my $root_dir = Poet::Environment::Generator->generate_environment_directory( |
54
|
|
|
|
|
|
|
root_dir => tempdir_simple('Poet-XXXX'), |
55
|
|
|
|
|
|
|
app_name => $app_name, |
56
|
|
|
|
|
|
|
quiet => 1, |
57
|
|
|
|
|
|
|
style => 'bare', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
return realpath($root_dir); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
method share_dir () { |
63
|
|
|
|
|
|
|
my $dist_root = dirname( dirname( dirname( dirname( realpath(__FILE__) ) ) ) ); |
64
|
|
|
|
|
|
|
my ($share_dir) = |
65
|
|
|
|
|
|
|
grep { -d $_ } ( "$dist_root/share", "$dist_root/lib/auto/share/dist/Poet" ); |
66
|
|
|
|
|
|
|
return $share_dir; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
method initialize_temp_env ($class:) { |
70
|
|
|
|
|
|
|
my $poet = $class->temp_env(@_); |
71
|
|
|
|
|
|
|
Poet::Environment->initialize_current_environment( env => $poet ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
method mech ($class:) { |
75
|
|
|
|
|
|
|
return Poet::Mechanize->new(@_); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# prevent YAML::XS warning...wtf |
79
|
|
|
|
|
|
|
YAML::XS::Dump( {} ); |
80
|
|
|
|
|
|
|
YAML::XS::Dump( {} ); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |