view release on metacpan or search on metacpan
erecipes/perl/Changes
erecipes/perl/lib/CGI/Ex/Recipes.pm
erecipes/perl/lib/CGI/Ex/Recipes/Add.pm
erecipes/perl/lib/CGI/Ex/Recipes/Cache.pm
erecipes/perl/lib/CGI/Ex/Recipes/DBIx.pm
erecipes/perl/lib/CGI/Ex/Recipes/Default.pm
erecipes/perl/lib/CGI/Ex/Recipes/Delete.pm
erecipes/perl/lib/CGI/Ex/Recipes/Edit.pm
erecipes/perl/lib/CGI/Ex/Recipes/Imager.pm
erecipes/perl/lib/CGI/Ex/Recipes/Install.pm
erecipes/perl/lib/CGI/Ex/Recipes/Template/Menu.pm
erecipes/perl/lib/CGI/Ex/Recipes/View.pm
erecipes/perl/README
erecipes/perl/t/00-load.t
erecipes/perl/t/01-cache.t
erecipes/perl/t/boilerplate.t
erecipes/perl/t/pod-coverage.t
erecipes/perl/t/pod.t
erecipes/templates/.htaccess
erecipes/templates/content/index/default.tthtml
erecipes/templates/content/index/edit.tthtml
erecipes/conf/Recipes.conf view on Meta::CPAN
# and so on...
template_args:
#(Not in TT)#default tt3
SYNTAX: tt3
#allow loading regular perl modules
LOAD_PERL: 1
INTERPOLATE: 1
#A hashref of mappings for plugin modules.
PLUGINS:
Menu: 'CGI::Ex::Recipes::Template::Menu'
PLUGIN_BASE: 'CGI::Ex::Recipes::Template'
SEMICOLONS: 0
#(Not in TT)#default 0
SHOW_UNDEFINED_INTERP: 0
STAT_TTL: 1
TRIM: 0
INCLUDE_PATH: ''
#we place here some specific for the app settings and macros which will be used in templates
PRE_PROCESS: templates/content/pre_process.tthtml
#we use it as application main template
erecipes/perl/bin/startup.pl view on Meta::CPAN
use utf8;
use strict;
use warnings;
use lib $ENV{SITE_ROOT} . "/perl/lib";
use CGI::Ex;
use CGI::Ex::Conf;
use Template::Alloy;
use CGI::Ex::Recipes;
our %CACHE_HASH = ();
use CGI::Ex::Recipes::Cache;
use CGI::Ex::Recipes::Template::Menu;
our $conf_obj = CGI::Ex::Conf->new({'paths'=>[$ENV{SITE_ROOT}],'directive'=>'MERGE'});
our $conf = $conf_obj->read($ENV{SITE_ROOT} .'/conf/Recipes.conf');
$conf->{base_dir_abs} = $ENV{SITE_ROOT};
$conf->{template_args}{INCLUDE_PATH} = $ENV{SITE_ROOT};
our $template_obj = Template::Alloy->new($conf->{template_args});
our $dbh = DBI->connect_cached(
'dbi:SQLite:dbname=' . $ENV{SITE_ROOT} . '/' . $conf->{'db_file'}, '', '',
{'private_'. __PACKAGE__ => __PACKAGE__ , RaiseError => 1}
);
erecipes/perl/lib/CGI/Ex/Recipes.pm view on Meta::CPAN
Get authentication arguments from configuration if there is such
and returns a hashref. The template_args are merged in also.
=head2 hash_base
The extra work done here is that we use L<Scalar::Util|Scalar::Util> to C<weaken>
the reference to the main application which we pass for use from within the templates and
template plugins. Without doing this we may have problems under persistent environments, such as
mod_perl. This is very handy when you need to dynamically generate HTML or
use the attached DBI object.
See L<CGI::Ex::Recipes::Template::Menu|CGI::Ex::Recipes::Template::Menu>, L<CGI::Ex::App|CGI::Ex::App>.
=head2 base_dir_abs
See also L<CGI::Ex::App|CGI::Ex::App>.
=head2 conf
Currently we use the old C<CGI::Ex::App::conf()>,
so the configuration file is found as it was before CGI::Ex 2.18.
See also L<CGI::Ex::App|CGI::Ex::App>.
erecipes/perl/lib/CGI/Ex/Recipes/Cache.pm view on Meta::CPAN
1;
__END__
=head1 NAME
CGI::Ex::Recipes::Cache - Naive caching in a database table
=head1 SYNOPSIS
Example from C<CGI::Ex::Recipes::Template::Menu::list_item()>:
# ... somewhere at the beginning of a method/subroutine which does heavy computations
if( $out = $app->cache->get($cache_key) ){ return $out; }
# ... here are your heavy calculations spread accross many lines
# making database calls generating HTML etc.
# ... just before the return of the method
#try cache support
$app->cache->set($cache_key, $out);
return $out;
=head1 DESCRIPTION
I found that when I cached in memory some output from CGI::Ex::Recipes::Template::Menu,
the performance under mod_perl jumped from:
...
Requests per second: 19.42 [#/sec] (mean)
Time per request: 154.441 [ms] (mean)
Time per request: 51.480 [ms] (mean, across all concurrent requests)
Transfer rate: 67.73 [Kbytes/sec] received
to
erecipes/perl/lib/CGI/Ex/Recipes/Default.pm view on Meta::CPAN
use warnings;
use strict;
use base qw(CGI::Ex::Recipes);
use utf8;
our $VERSION = '0.03';
sub info_complete { 0 }
sub skip { 0 }
# now the list of items is produced by CGI::Ex::Recipes::Template::Menu
1;# End of CGI::Ex::Recipes::Default
__END__
=head1 NAME
CGI::Ex::Recipes::Default - The default step!
erecipes/perl/lib/CGI/Ex/Recipes/Template/Menu.pm view on Meta::CPAN
package CGI::Ex::Recipes::Template::Menu;
use utf8;
use warnings;
use strict;
#use CGI::Ex::Dump qw(debug dex_warn);
our $VERSION = '0.02';
sub load { # called as Menu->load($context)
my ( $class, $context ) = @_;
#we may do other things beside just returning the class name if we need.
return $class; # returns 'Menu'
}
sub new { # called as Menu->new($context)
my ( $class, $context, @params ) = @_;
bless {
_CONTEXT => $context,
_PARAMS => $params[0],
},
$class; # returns blessed Menu object
}
sub run {
my ( $self, @args ) = @_;
if ( $args[0] == 'default_map' ) {
return 'hi ';
}
return $self->{_CONTEXT}->stash->get('app');
}
erecipes/perl/lib/CGI/Ex/Recipes/Template/Menu.pm view on Meta::CPAN
my $self = shift;
my $item = shift || die('please provide a recipe item.') . $!;
my $app = $self->{app} ||= $self->get('app');
my $cgix = $app->cgix;
my $out;
my $cache_key = 'list_item_' . $item->{id} . ( $app->is_authed ? 1 : '' );
#try cache support
if( $out = $app->cache->get($cache_key) ){ return $out; }
if ( $self->{'recurse_level'} >= $self->{'_PARAMS'}{recurse} ) {
return $cgix->li( { class => 'recipes', style => 'color:red' },
'Max recursion reached. ' . 'If you want more: USE menu = Menu(recurse => 10000);' );
}
if ( $item->{is_category} ) {
$self->{'recurse_level'}++;#ТÐÐÐ:make it work
foreach my $list_item (
@{ $app->recipes(
[qw(id pid is_category title)],
{ pid => $item->{id},
id => { '!=', $item->{id} },
},
erecipes/perl/lib/CGI/Ex/Recipes/Template/Menu.pm view on Meta::CPAN
#shows controls for add,edit,delete if user is_authed
sub controls {
}
sub context { $_[0]->{_CONTEXT} }
sub stash { $_[0]->{_CONTEXT}->stash }
sub get { shift->stash->get(@_) }
sub set { shift->stash->set(@_) }
1; # End of CGI::Ex::Recipes::Template::Menu
__END__
=head1 NAME
CGI::Ex::Recipes::Template::Menu - Implements all sorts of menus for the application
=head1 VERSION
Version 0.02
=head1 SYNOPSIS
[%# in some template altought it may be loaded first in the pre_process.tthtml %]
[% menu = USE Menu %]
[% menu.recipes_map(0) %]
...
=head1 METHODS
=head2 recipes_map
Called in default.tthtml. Lists all categorie under $id and items within them.
erecipes/perl/t/00-load.t view on Meta::CPAN
use lib qw( ./erecipes/perl/lib );
}
use Test::More tests => 10;
BEGIN {
use_ok( 'CGI::Ex::Recipes' );
use_ok( 'CGI::Ex::Recipes::View' );
use_ok( 'CGI::Ex::Recipes::Edit' );
use_ok( 'CGI::Ex::Recipes::Add' );
use_ok( 'CGI::Ex::Recipes::Delete' );
use_ok( 'CGI::Ex::Recipes::Template::Menu' );
use_ok( 'CGI::Ex::Recipes::DBIx' );
use_ok( 'CGI::Ex::Recipes::Default' );
use_ok( 'CGI::Ex::Recipes::Imager' );
use_ok( 'CGI::Ex::Recipes::Cache' );
}
diag( "Testing CGI::Ex::Recipes $CGI::Ex::Recipes::VERSION, Perl $], $^X" );
erecipes/perl/t/boilerplate.t view on Meta::CPAN
);
}
module_boilerplate_ok('lib/CGI/Ex/Recipes.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/View.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/Edit.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/Add.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/Delete.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/Template/Menu.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/DBIx.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/Default.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/Imager.pm');
module_boilerplate_ok('erecipes/perl/lib/CGI/Ex/Recipes/Cache.pm');
erecipes/templates/content/index/default.tthtml view on Meta::CPAN
<div id="content">
<h2>About:</h2>
[%# DUMP Menu.list_items(0) %]
[%# DUMP app.categories %]
[%# DUMP app.recipes %]
[% success %]
[% menu.recipes_map( id ) %]
</div>
erecipes/templates/content/pre_process.tthtml view on Meta::CPAN
[%
#setting up variables,blocks,macros,etc which are available for all templates
base_url = app.cgix.object.url( base=1 );
relative_url = app.cgix.object.url( relative=1 );
install_path_url = script_name.replace( relative_url _ '.*$','');
url = app.cgix.object.url();
dbh = app.dbh;
today = app.strftmime("%Y-%m-%d ", app.now);
#load some plugin
USE menu = Menu({recurse => 5});
%]
[%#
well some macros allso
-%]
[%- MACRO option( item ) BLOCK; %]
<option value="[% item.id %]">[% item.title %]</option>
[% END -%]
[%- MACRO optgroup( optlist ) BLOCK; -%]
lib/CGI/Ex/Recipes.pm view on Meta::CPAN
Get authentication arguments from configuration if there is such
and returns a hashref. The template_args are merged in also.
=head2 hash_base
The extra work done here is that we use L<Scalar::Util|Scalar::Util> to C<weaken>
the reference to the main application which we pass for use from within the templates and
template plugins. Without doing this we may have problems under persistent environments, such as
mod_perl. This is very handy when you need to dynamically generate HTML or
use the attached DBI object.
See L<CGI::Ex::Recipes::Template::Menu|CGI::Ex::Recipes::Template::Menu>, L<CGI::Ex::App|CGI::Ex::App>.
=head2 base_dir_abs
See also L<CGI::Ex::App|CGI::Ex::App>.
=head2 conf
Currently we use the old C<CGI::Ex::App::conf()>,
so the configuration file is found as it was before CGI::Ex 2.18.
See also L<CGI::Ex::App|CGI::Ex::App>.