Egg::Helper - Helper module for Egg.


Egg-Release documentation Contained in the Egg-Release distribution.

Index


Code Index:

NAME

Top

Egg::Helper - Helper module for Egg.

DESCRIPTION

Top

This module is started by the helper script.

Helper of standard appending.

* Egg::Helper::Build::Module.

The template of the Perl module is generated.

* Egg::Helper::Build::Plugin.

The template of the plug-in module is generated.

* Egg::Helper::Build::Project.

The project is constructed.

* Egg::Helper::Build::Prototype.

'prototype.js' etc. are output.

* Egg::Helper::Config::YAML.

The model of the configuration of the YAML form is generated.

* Egg::Helper::Util::Tester.

Test of project application.

* Egg::Helper::Util::VirtualProject.

Virtual project for package test.

METHODS

Top

run

When the helper script is started, this method is called.

helper_tools

Especially, nothing is done. Helper object is only returned.

The thing used to cause some actions as the file is made before the Egg::Helper::Util::VirtualProject object is acquired in the package test etc. is assumed.

  use Egg::Helper;

  my $tool= Egg::Helper->helper_tools;

  $tool->helper_create_file(join '', <DATA>);
  .....

It is a project object that this method returns that succeeds to Egg::Helper::Util::Base.

helper_script

The code of the helper scripting to generate the project is returned.

To generate the helper script, as follows is done.

  % perl -MEgg::Helper -e 'Egg::Helper->helper_script' > /path/to/egg_helper.pl

I think that the generated script is convenient when it outputs to the place that passing passed, and the execution attribute is given at the right time.

And, the project is generated as follows.

  % egg_helper.pl project [PROJECT_NAME] -o/path/to

* Alias = out

SEE ALSO

Top

Egg, Egg::Release, Egg::Helper::Util::Base,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Egg-Release documentation Contained in the Egg-Release distribution.

package Egg::Helper;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: Helper.pm 337 2008-05-14 12:30:09Z lushe $
#
use strict;
use warnings;
use Carp qw/ croak /;
use base qw/ Egg::Helper::Util::Base /;

our $VERSION= '3.01';

$SIG{__DIE__}= sub { Egg::Error->throw(@_) };

my %A= (
  project => 'Build::Project',
  vtest   => 'Util::VirtualProject',
  tester  => 'Util::Tester',
  tools   => 'Util::Tools',
  );
my %Alias= (
  B => 'Build',
  C => 'Controller',
  D => 'Dispatch',
  H => 'Helper',
  L => 'Log',
  M => 'Model',
  P => 'Plugin',
  R => 'Response',
  U => 'Util',
  V => 'View',
  m => 'Module',
  r => 'Request',
  );
my($modenow, $contextnow);

sub run {
	my $class= shift;
	my $mode = ucfirst(shift) || croak q{ I want 'MODE'. };
	my $attr = shift || {};
	if (my $a= $A{lc $mode}) { $mode= $a }
	if ($mode=~m{^([A-Za-z])[\:\-]+}) {
		if (my $alias= $Alias{$1}) { $mode=~s{^[^\:\-]+} [$alias] }
	}
	$mode=~s{\-} [::]g;
	$mode=~s{([^\:])\:([^\:])} [$1.'::'.$2]eg;
	$mode=~s{\:([a-z])} [':'. ucfirst($1)]eg;
	($modenow and $modenow eq $mode)
	    and die qq{ '$modenow' mode is operating. };
	if ($contextnow) {
		my %conf= (
		  %{$contextnow->config},
		  project_name => ($attr->{project_name} || undef),
		  helper_option=> $attr,
		  );
		$contextnow->config(\%conf);
		return 	$contextnow->_start_helper;
	}
	my $pkg= "Egg::Helper::$mode";
	$pkg->require || return $class->_helper_help(
	  $@=~/^\s*Can\'t\s+locate/
	     ? qq{ Typing error of mode name. [$mode] }
	     : qq{ Script error: $@ }
	  );
	my $plugins;
	if (my $loads= $pkg->can('_helper_load_plugins')) {
		$plugins= $loads->() || [];
	} else {
		$plugins= [];
	}
	$contextnow= $class->_helper_context($pkg, $plugins, $attr);
	$contextnow->_start_helper;
}
sub helper_tools {
	my $class= shift;
	$class->_helper_context('Egg::Helper::Dummy', [], @_);
}
sub _helper_context {
	my($class, $pkg, $plugins)= splice @_, 0, 3;
	my $attr   = $_[1] ? {@_}: ($_[0] || {});
	my $handler= $ENV{EGG_HELPER_CLASS} || 'Egg::Helper::Project';
	$attr->{start_dir}= $class->helper_current_dir;
	$attr->{project_root} ||= $class->helper_tempdir || $attr->{start_dir};
	$attr->{root}= $attr->{project_root};
	$handler->__import($pkg, $plugins, {
	  project_name => ($attr->{project_name_orign} || 'EggHelper'),
	  root         => $attr->{project_root},
	  start_dir    => $attr->{start_dir},
	  helper_option=> $attr,
	  });
	$handler->new;
}
sub helper_script {
	print STDOUT <<SCRIPT;
#!@{[ Egg::Helper::Util::Base->helper_perl_path ]}
use Egg::Helper;
Egg::Helper->run( shift(\@ARGV) );
SCRIPT
}
*out= \&helper_script;

package Egg::Helper::Project;
use strict;
use warnings;
require Egg;

our @ISA= qw/ Egg::Helper::Util::Base /;
our $START_DIR;

sub __import {
	my($class, $pkg, $plugins, $attr)= @_;
	$ENV{"EGG::HELPER::PROJECT_DISPATCH_CLASS"}= 0;
	Egg->import(@$plugins);
	unshift @ISA, $pkg;
	__PACKAGE__->_startup($attr);
	no strict 'refs';  ## no critic.
	no warnings 'redefine';
	*{"${class}::namespace"}= sub { $_[0]->config->{project_name} };
	*{"${class}::project_name"}= $class->can('namespace');
	$START_DIR= $attr->{start_dir} || "";
	$class;
}
END { chdir($START_DIR) if $START_DIR };  ## no critic.

package Egg::Helper::Dummy;

1;

__END__