| 1 | package Catalyst::Plugin::CodeEval; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 1 | ▶ | use PadWalker qw(peek_my); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 1 | our $VERSION = '0.012'; | |||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 1 | my($Revision) = '$Id: CodeEval.pm,v 1.6 2006/02/14 09:40:47 Sho Exp $'; | |||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | Catalyst::Plugin::CodeEval - Module for huge Catalyst application development. | ||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | # in your catalyst application. | ||||||||||||||||||
| 19 | use Catalyst 'CodeEval'; | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | $c->code_eval('perl_script.pl'); | ||||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | =cut | ||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | =head1 | ||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | # create file in your catalyst application directory. | ||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | # $c->config->home . /code_eval/perl_script.pl | ||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | $c->log->debug('bar bar bar'); | ||||||||||||||||||
| 32 | $c->log->debug('$c->req->base->host : '.$c->req->base->host); | ||||||||||||||||||
| 33 | 1; | ||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | perl script file is executed by using eval. | ||||||||||||||||||
| 38 | happiness visits when starting of your application is very slow. | ||||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | =head1 METHODS | ||||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | =head2 code_eval | ||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | perl script file is executed by using eval. | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | =cut | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 0 | ▶ | sub code_eval { | ||||||||||||||||
|
Subroutine
code_eval: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||
| 49 | 0 | my $c = shift; | |||||||||||||||||
| 50 | 0 | my $CodeEval_code_eval_file = shift; | |||||||||||||||||
| 51 | 0 | my $CodeEval_uplevel_variable = peek_my(1); | |||||||||||||||||
| 52 | 0 | my $CodeEval_code_sourcecode; | |||||||||||||||||
| 53 | 0 | eval { | |||||||||||||||||
| 54 | 0 | $CodeEval_code_sourcecode = $c->read_code($CodeEval_code_eval_file); | |||||||||||||||||
| 55 | }; | ||||||||||||||||||
| 56 | 0 | ▶ | if($@) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 57 | 0 | $c->log->debug("+++++ CodeEval : load script file error : \n$@"); | |||||||||||||||||
| 58 | 0 | return 1; | |||||||||||||||||
| 59 | } | ||||||||||||||||||
| 60 | |||||||||||||||||||
| 61 | 0 | my $CodeEval_variable_code; | |||||||||||||||||
| 62 | 0 | foreach my $key (grep($_ ne '$c', keys(%{$CodeEval_uplevel_variable}))) { | |||||||||||||||||
| 63 | 0 | ▶ | if($key =~ /^\$/) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 64 | 0 | $CodeEval_variable_code .= "my $key = \${\$CodeEval_uplevel_variable->{'$key'}};\n"; | |||||||||||||||||
| 65 | } elsif($key =~ /^\@/) { | ||||||||||||||||||
| 66 | 0 | $CodeEval_variable_code .= "my $key = \@{\$CodeEval_uplevel_variable->{'$key'}};\n"; | |||||||||||||||||
| 67 | } elsif($key =~ /^\%/) { | ||||||||||||||||||
| 68 | 0 | $CodeEval_variable_code .= "my $key = \%{\$CodeEval_uplevel_variable->{'$key'}};\n"; | |||||||||||||||||
| 69 | } else { | ||||||||||||||||||
| 70 | 0 | $CodeEval_variable_code .= "my $key = \$CodeEval_uplevel_variable->{'$key'};\n"; | |||||||||||||||||
| 71 | } | ||||||||||||||||||
| 72 | } | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | # $c->log->debug("++++ CodeEval : eval this code +++++\n".$CodeEval_variable_code . $CodeEval_code_sourcecode); | ||||||||||||||||||
| 75 | 0 | my $rt = eval($CodeEval_variable_code . $CodeEval_code_sourcecode); | |||||||||||||||||
| 76 | 0 | ▶ | if($@) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 77 | 0 | $c->log->debug("+++++ CodeEval : execute error : \n$@"); | |||||||||||||||||
| 78 | } else { | ||||||||||||||||||
| 79 | 0 | $c->log->debug("+++++ CodeEval : execute end : return $rt +++++"); | |||||||||||||||||
| 80 | } | ||||||||||||||||||
| 81 | 0 | return $rt; | |||||||||||||||||
| 82 | } | ||||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | =head2 read_code | ||||||||||||||||||
| 85 | |||||||||||||||||||
| 86 | read file | ||||||||||||||||||
| 87 | |||||||||||||||||||
| 88 | =cut | ||||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | 0 | ▶ | sub read_code { | ||||||||||||||||
|
Subroutine
read_code: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||
| 91 | 0 | my $c = shift; | |||||||||||||||||
| 92 | 0 | my $file = shift; | |||||||||||||||||
| 93 | |||||||||||||||||||
| 94 | 0 | my $script_file = $c->path_to('code_eval',$file); | |||||||||||||||||
| 95 | 0 | $c->log->debug("+++++ CodeEval : load script file ($script_file) +++++"); | |||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | 0 | ▶ | open(CODEFILE, $script_file) or die "can not open $script_file\n"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 98 | 0 | my $code = join("",<CODEFILE>); | |||||||||||||||||
| 99 | 0 | close(CODEFILE); | |||||||||||||||||
| 100 | 0 | return $code | |||||||||||||||||
| 101 | } | ||||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | =head1 SEE ALSO | ||||||||||||||||||
| 104 | |||||||||||||||||||
| 105 | L<Catalyst> L<PadWalker> | ||||||||||||||||||
| 106 | |||||||||||||||||||
| 107 | =head1 AUTHOR | ||||||||||||||||||
| 108 | |||||||||||||||||||
| 109 | Shota Takayama, C<shot[atmark]bindstorm.jp> | ||||||||||||||||||
| 110 | |||||||||||||||||||
| 111 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||
| 114 | the same terms as Perl itself. | ||||||||||||||||||
| 115 | |||||||||||||||||||
| 116 | =cut | ||||||||||||||||||
| 117 | |||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||