The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Egg::Util - Standard method of utility for Egg.

DESCRIPTION

This module offers the method of utility for Egg.

METHODS

page_title ([TITLE_STRING])

The title of the output contents is set.

The value is substituted for $e->stash->{page_title}.

When TITLE_STRING was omitted, the value of the defined value or $e->config->{title} had already been used.

  $e->page_title('Hoge Page');

debug

True is restored if it is operating by debug mode.

flag

Refer to the value of the flag set by the start option. The value cannot be set.

 use Egg qw/ -MyFlag /;

  if ($e->flag('MyFlag')) {
     ...........

snip

Refer to the value though Egg::Response divides the URI by '/' at each request and it preserves it as ARRAY reference.

 my($path1, $path2)= @{$e->snip};

action

The ARRAY reference to divide request URI to the place matched with dispatch_map by '/' is returned.

  my($path1, $path2)= @{$e->action};

stash ([KEY], [VALUE]);

It is a place where the common data is treated.

When KEY is given, data corresponding to KEY is returned.

When KEY and VALUE are given, data corresponding to KEY is set.

When the argument is not given, the HASH reference of the common data is returned.

  my $tmpl= $e->stash('template');
  
  $e->stash( template => 'hoge.tt' );
  
  my $tmpl= $e->stash->{template};

path_to ([ARG1], [ARG2])

When the argument is omitted, the value of $e->config->{root} is returned. Project route in a word.

When ARG1 is given, "$e->config->{root}/ARG1" is returned.

When ARG2 is given, "$e->config->{dir}{ARG1}/ARG2" is returned.

  my $project_root= $e->path_to;
  
  my $cache_dir = $e->path_to('cache');
  
  my $yaml= $e->path_to('etc', 'mydata.yaml');

uri_to ([URI], [ARGS])

The result of the URI module is returned.

  my $uri= $e->uri_to($e->req->host_name);

snip2template ([NUM])

The template name is generated with the value to the element given with NUM for $e->snip.

  my $template= $e->snip2template(3);

setup_error_header

The content set in call Egg::Response when the error etc. occur is initialized and the header for the error etc. are set.

get_config

This is a convenient method to the reference to the configuration in which Egg system module is defined in the parents package.

egg_var ([PARAM], [STRING])

It is a method for the use of a peculiar replace function to Egg.

The HASH reference for the substituted data is given to PARAM.

<e.[name]> of STRING is replaced by the value of PARAM corresponding to [name].

Even if it is <e.[name].[name2]>, the key can be handled well.

  my $param= { data => { hoge=> '123' } };
  my $text = "abc <e.data.hoge>";
  $e->egg_var($param, $text);
  print $text;  # -> abc 123

egg_var_deep ([PARAM], [VALUE])

It is a method for the use of a peculiar replace function to Egg.

Only the character string is treated as for egg_var, and if VALUE is HASH and ARRAY, the contents also recurrently try substituting here.

  my $param= { hoge=> '123' };
  my $hash = { data=> 'abc <e.hoge>' };
  $e->egg_var_deep($param, $hash);
  print $hash->{data}; # -> abc 123

error ([MESSAGE])

To do some error processing, the error message is set.

The message is set in $e->errstr and $e->stash->{error}.

Because this method always returns 0, it is not possible to use it to judge the error situation of the occurrence. Please look at $e->errstr and $e->stash->{error}.

  $e->error('Intarnal Error.');
  
  if ($e->errstr) {
     .......

SEE ALSO

Egg::Release, Tie::Hash::Indexed, URI,

AUTHOR

Masatoshi Mizuno <lushe@cpan.org>

Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>.

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.