line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Helper::Util::VirtualProject; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: VirtualProject.pm 337 2008-05-14 12:30:09Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
1
|
|
|
1
|
|
722
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
52
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
9
|
1
|
|
|
1
|
|
7
|
use base qw/ Class::Data::Inheritable /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
578
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION= '3.00'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _start_helper { |
14
|
0
|
|
|
0
|
|
|
my($self)= @_; |
15
|
0
|
|
|
|
|
|
my %option; |
16
|
|
|
|
|
|
|
{ |
17
|
0
|
|
|
|
|
|
my $c= $self->config->{helper_option}; |
|
0
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
%option= $c->{vtest_config} ? (%$c, %{$c->{vtest_config}}): %$c; |
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
}; |
20
|
0
|
|
0
|
|
|
|
my $project= $option{vtest_name} ||= 'Vtest'; |
21
|
0
|
0
|
|
|
|
|
if ($option{helper_test}) { |
22
|
0
|
|
|
|
|
|
@ARGV= (); |
23
|
0
|
|
|
|
|
|
$self->config->{root}= Egg::Helper->helper_tempdir; |
24
|
|
|
|
|
|
|
} |
25
|
0
|
0
|
|
|
|
|
unless (__PACKAGE__->can('base_root')) { |
26
|
0
|
|
|
|
|
|
unshift @INC, $self->config->{start_dir}. "/lib"; |
27
|
0
|
|
|
|
|
|
__PACKAGE__->mk_classdata('base_root'); |
28
|
0
|
|
|
|
|
|
__PACKAGE__->base_root($self->config->{root}); |
29
|
|
|
|
|
|
|
} |
30
|
0
|
0
|
|
|
|
|
if (my $scode= $option{start_code}) { |
31
|
0
|
0
|
|
|
|
|
eval $scode; $@ and die $@; ## no critic. |
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
delete($option{start_code}); |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
0
|
|
|
|
$option{project_root}= $option{root}= |
35
|
|
|
|
|
|
|
$option{vtest_root} || __PACKAGE__->base_root. "/$project"; |
36
|
0
|
|
|
|
|
|
$option{start_dir}= $self->helper_current_dir; |
37
|
0
|
0
|
|
|
|
|
$self->helper_create_dir($option{root}) unless -e $option{root}; |
38
|
0
|
|
|
|
|
|
$self->helper_chdir($option{root}); |
39
|
0
|
0
|
|
|
|
|
if (my $files= $option{create_files}) { |
40
|
0
|
|
|
|
|
|
$self->helper_create_files($files, $self->config); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
$self->_create_project($project); |
43
|
0
|
|
|
|
|
|
unshift @INC, "$option{root}/lib"; |
44
|
0
|
|
|
|
|
|
$project->_vtest_import(\%option); |
45
|
0
|
0
|
|
|
|
|
if (my $helper= $option{helper_test}) { |
46
|
0
|
0
|
|
|
|
|
$helper->require or die $@; |
47
|
1
|
|
|
1
|
|
8
|
no strict 'refs'; ## no critic. |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
66
|
|
48
|
0
|
|
|
|
|
|
unshift @{"${project}::ISA"}, $helper; |
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
0
|
0
|
|
|
|
|
if (my $methods= $option{create_methods}) { |
51
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; ## no critic. |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
52
|
1
|
|
|
1
|
|
7
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
184
|
|
53
|
0
|
|
|
|
|
|
while (my($method, $code)= each %$methods) { |
54
|
0
|
|
|
|
|
|
*{"${project}::$method"}= $code; |
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
$project->new; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
sub _create_project { |
60
|
0
|
|
|
0
|
|
|
my $self= shift; |
61
|
0
|
|
0
|
|
|
|
my $p= shift || die q{I want project name.}; |
62
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; ## no critic. |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
63
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
377
|
|
64
|
0
|
|
|
|
|
|
${"${p}::VERSION"}= '0.01'; |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
push @{"${p}::ISA"}, 'Egg::Helper::Util::Base'; |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
push @{"${p}::ISA"}, 'Egg::Helper::Util::VirtualProject'; |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
*{"${p}::_vtest_import"}= sub { |
68
|
0
|
|
|
0
|
|
|
my($class, $conf)= @_; |
69
|
0
|
|
|
|
|
|
my %c= %$conf; |
70
|
0
|
|
|
|
|
|
$c{project_name}= $p; |
71
|
0
|
|
|
|
|
|
my $pkg_uc= uc $p; |
72
|
0
|
0
|
|
|
|
|
$ENV{"${pkg_uc}_DISPATCH_CLASS"}= 0 |
73
|
|
|
|
|
|
|
unless defined($ENV{"${pkg_uc}_DISPATCH_CLASS"}); |
74
|
0
|
|
|
|
|
|
$ENV{EGG_IMPORT_PROJECT}= $p; |
75
|
0
|
0
|
|
|
|
|
Egg->import(@{$c{vtest_plugins} || []}); |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
delete $c{dir}; |
77
|
0
|
|
|
|
|
|
$p->egg_startup(\%c); |
78
|
0
|
|
0
|
|
|
|
$p->dispatch_map($c{vtest_dispatch_map} || {}); |
79
|
0
|
|
|
|
|
|
}; |
80
|
0
|
|
|
|
|
|
*{"${p}::DESTROY"}= sub { |
81
|
0
|
|
|
0
|
|
|
my($proto)= @_; |
82
|
0
|
0
|
|
|
|
|
return $proto if $proto->{egg_startup}; |
83
|
0
|
0
|
|
|
|
|
if (my $root= $proto->config->{root}) { |
84
|
0
|
|
|
|
|
|
$proto->helper_remove_dir($root); |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
$proto; |
87
|
0
|
|
|
|
|
|
}; |
88
|
0
|
|
|
|
|
|
$self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Egg::Helper::Util::VirtualProject - Virtual project for package test. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
use Test::More tests=> 10; |
102
|
|
|
|
|
|
|
use Egg::Helper; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $e= Egg::Helper->run('vtest'); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 DESCRIPTION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
It is a helper who offers the virtual project environment to use it in the package |
109
|
|
|
|
|
|
|
test of the module. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
The object of a virtual project is passed and 'Vtest' is passed to the 'run' method |
112
|
|
|
|
|
|
|
of obtaining L<Egg::Helper>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $e= Egg::Helper->run('vtest'); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
And, it is treated since the first argument as a configuration of the project. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
The name of a virtual project is usual 'Vtest'. |
119
|
|
|
|
|
|
|
'project_name' is set to the configuration and it is revokable. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $e= Egg::Helper->run( vtest => { |
122
|
|
|
|
|
|
|
project_name => 'MyProject', |
123
|
|
|
|
|
|
|
} ); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
The plug-in to want to load into a virtual project sets 'plugins' to the configuration. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $e= Egg::Helper->run( vtest => { |
128
|
|
|
|
|
|
|
plugins => [qw/ -Debug Encode Filter /], |
129
|
|
|
|
|
|
|
}); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
* The flag is specified in 'plugins'. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
It is executed before the object is generated when the code reference is set in |
134
|
|
|
|
|
|
|
'start_code'. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $e= Egg::Helper->run( vtest => { |
137
|
|
|
|
|
|
|
start_code => sub { |
138
|
|
|
|
|
|
|
.................... |
139
|
|
|
|
|
|
|
......... |
140
|
|
|
|
|
|
|
}, |
141
|
|
|
|
|
|
|
}); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The method that wants to be generated with 'create_methods' can be set. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $e= Egg::Helper->run( vtest => { |
146
|
|
|
|
|
|
|
create_methods => { |
147
|
|
|
|
|
|
|
hoo => sub { |
148
|
|
|
|
|
|
|
my($e)= @_; |
149
|
|
|
|
|
|
|
........ |
150
|
|
|
|
|
|
|
}, |
151
|
|
|
|
|
|
|
boo => sub { |
152
|
|
|
|
|
|
|
my($e)= @_; |
153
|
|
|
|
|
|
|
........ |
154
|
|
|
|
|
|
|
}, |
155
|
|
|
|
|
|
|
}, |
156
|
|
|
|
|
|
|
}); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
The root directory of a virtual project is made from the project name in the place |
159
|
|
|
|
|
|
|
obtained by 'helper_tempdir' of L<Egg::Helper>. Moreover, the work directory moves |
160
|
|
|
|
|
|
|
to this root directory at the same time as generating the object. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Please set it in the configuration when 'dispatch_map' is necessary. |
163
|
|
|
|
|
|
|
You may separately generate the Dispatch module of course and read. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Please intitule an individual project in 'project_name' when two or more virtual |
166
|
|
|
|
|
|
|
projects are necessary. When two or more virtual projects are generated with the |
167
|
|
|
|
|
|
|
same name, the inconvenience of the redefine of the method etc. is generated. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 SEE ALSO |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L<Egg::Release>, |
172
|
|
|
|
|
|
|
L<Egg::Helper>, |
173
|
|
|
|
|
|
|
L<Class::Data::Inheritable>, |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
184
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
185
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|