Egg::Helper::VirtualTest - The virtual test environment for Egg project.


  use Egg::Helper::VirtualTest;
  my $vr= Egg::Helper::VirtualTest->new;
    controller   => { egg_includes => [qw/ AnyPlugin /] },
    create_files => \@files,
    config => {
      hoo  => '.....',
      hoge => '...',
  my $e= $vr->egg_context;
  my $mech= $vr->mech_get('/request_uri');
  print $mech->content;


An executable virtual environment is constructed for the test of the Egg project.

A virtual environment can control the composition by HASH passed to the prepare method.

Moreover, the result to a virtual request and the operation of the script are verifiable it according to WWW::Mechanize::CGI.


new ( [OPTION_HASH] )


It comes to be able to access given OPTION_HASH by the option method.

Suitable following initialize is done, and the object is returned.

  • project_name

    If project_name of OPTION_HASH is undefined, 'VirtualTest' is set.

  • start_dir

    Current directory of execution.

  • project_root

    If temp_dir of OPTION_HASH is undefined, the work directory is acquired temporarily and set from File::Temp.

  • project_already

    When project_root already exists when 'already_ok' of OPTION_HASH is undefined, the exception is generated.

  • prepare

    It passes it to the prepare method if there is prepare in OPTION_HASH.

prepare ( [PREPAR_HASH] )

A virtual project is constructed according to PREPAR_HASH.

When PREPAR_HASH is omitted, all virtual projects are constructed with Defolt.

The item evaluated with PREPAR_HASH is as follows.

  • controller => [CONTROLLER_HASH]

    Setting concerning controller.

    The content evaluates the following items with HASH without fail.

    • egg => [PLUGIN_OR_FLAG_ARRAY]

      The plugin and the flag that makes it load are specified with ARRAY.

      Default is [qw/Dispatch::Standard Debugging Log/]

        controller => { egg => [qw/ Dispatch::Fast Debugging Log /] },
    • egg_includes => [PLUGIN_OR_FLAG_ARRAY]

      List of plugin and flag added to value of egg.

        controller => { egg_includes => [qw/ AnyPlugin /] },
    • egg_debug => [BOOL]

      '-Debug' is added to the list of the plugin and the flag.

        controller => { egg_debug => 1 },
    • default_mode => [DEFAULT_MODEL]

      Name of default_mode defined in default_mode.

        controller => { default_mode => 'default' },
    • egg_run_modes => [RUN_MODES_TEXT]

      The setting of run_modes is set as it is in the text.

        my $run_modes= <<'END_MODE';
          _default => sub {},
          hoo => sub {
            my($self, $e)= @_;
          hoge => sub {},
        controller => { run_modes => $run_modes },
    • egg_mode_param => [PARAM_NAME]

      Name of mode_param defined in mode_param.

        controller => { mode_param => 'mode' },
    • first_code = [CODE_TEXT]

      Script code that wants to be included in controller's first half.

        my $first_code= <<'END_CODE';
        use MyApp::Tools;
        controller => { first_code => $first_code },
    • last_code => [CODE_TEXT]

      Script code that wants to be included in controller's latter half.

        my $last_code = <<'END_CODE';
        sub last_code {
          my($self, $e)= @_;
        controller => { last_code => $last_code },
    • version => [VERSION_NUMBER]

      Version of controller who generates it.

        controller => { version => '1.00' },
  • config => [CONFIG_HASH]

    • title => [TITLE_TEXT]

      Default is $vr->project_name.

    • root => [PROJECT_ROOT_PATH]

      Default is $vr->project_root.

    • template_path => [PATH_ARRAY]

      Default is ["$vr->project_root/root", "$vr->project_root/comp"]


      Default is a setting of Template (HTML::Template).

    • default_view_mason => [BOOL]

      Mason is set to VIEW if this value is effective when the setting of VIEW is undefined.

    • ... etc.

      Additionally, please refer to the document of Egg for details for the configuration.

  • create_files => [FILE_DATA_ARRAY]

    A new file is generated according to FILE_DATA_ARRAY.

    Each item of ARRAY is HASH passed to Egg::Helper->save_file.

     * Because generation does project_root to the starting point, filename
       can be specified by relativity PATH.
      create_files => [
          filename => "etc/hoge.txt",
          value    => "<\$e.project_name> \n OK \n",
          filename => "bin/",
          filetype => "script",
          value    => "print 'OK';",
  • create_dirs => [DIR_LIST_ARRAY]

    An empty directory is made according to DIR_LIST_ARRAY.

      create_dirs => [qw{ tmp/myapp cache/content/myapp }],


$SIG{__WARN__}= sub {}.


STDOUT is output temporary.


STDERR is output temporary.


All 'disable_warn' and 'disable_stdout' and 'disable_stderr' is done at a time.


The object of a virtual project is returned.

  my $e= $vr->egg_context;


The object of a virtual project of the '_prepare_model' and '_prepare_view' and '_prepare' execution is returned.

  my $e= $vr->egg_pcomp_context;


‰¼‘zƒvƒƒWƒFƒNƒg‚Ì handler ƒƒ\ƒbƒh‚ðƒR[ƒ‹‚µ‚Ü‚·B


helper_run ( [MODE], [ANY_NAME], [OPTION] )

The helper script is operated on a virtual project.

MODE is not omissible.

  $vr->helper_run('Plugin:Helper', 'NewName', { ... options });


If the include of WWW::Mechanize::CGI succeeds, true is returned.

mechanize ( [OPTION_HASH] )

The object of WWW::Mechanize::CGI is returned.

OPTION_HASH is an option to pass to WWW::Mechanize::CGI.

mech_get ( [VR_REQUEST_URI], [OPTION] )

Virtual GET is requested to VR_REQUEST_URI.

OPTION is an option to pass to 'mechanize' method.

When the return value is received with ARRAY, the object of the project after CGI is executed can be received.

  my($mech, $e)= $vr->mech_get('/get_request');
  print $mech->content;
  if ($e->param('check_param')) { print "OK" }


Virtual POST is requested to VR_REQUEST_URI.

QUERY_DATA_HASH is a parameter passed to CGI.

OPTION is an option to pass to 'mechanize' method.

  my $mech= $vr->mech_post('/post_request', { foo => 'test', hoge=> 'OK' });
  print $mech->content;

* When upload is tested, it is L as for QUERY_DATA_HASH. <HTTP::Request::Common> Please give it by the form that passes.

  my $proot= $vr->project_root;
  my($mech, $e)= $vr->mech_post('/post_request', {
    Content_Type => 'form-data',
    Content => [
      upload1 => ["$proot/data/upload.txt" ],
      upload2 => ["$proot/data/upload.html"],
      param1  => 'test',
  my $upload= $e->request->upload('upload1');
  if ($upload->filename) { print "OK" }

* It is necessary to load the 'Upload' plugin into the test of upload.


File::Temp, WWW::Mechanize::CGI, HTTP::Request::Common, Egg::Helper, Egg::Release,


Masatoshi Mizuno <>


Copyright (C) 2007 by Bee Flag, Corp. <>, All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 394:

Non-ASCII character seen before =encoding in '‰¼‘zƒvƒƒWƒFƒNƒg‚Ì'. Assuming ISO8859-1