App-ZofCMS
view release on metacpan or search on metacpan
bin/zofcms_helper
dist.ini
examples/config.txt
examples/data/base.tmpl
examples/data/comments.tmpl
examples/data/index.tmpl
examples/fileicons.tar.gz
examples/index.tmpl
examples/index2.tmpl
examples/plug.pm
examples/templates/404.tmpl
examples/templates/comments.tmpl
examples/templates/index.tmpl
examples/test_example.pl
lib/App/ZofCMS.pm
lib/App/ZofCMS/Config.pm
lib/App/ZofCMS/Output.pm
lib/App/ZofCMS/Plugin.pm
lib/App/ZofCMS/Plugin/AccessDenied.pm
lib/App/ZofCMS/Plugin/AntiSpamMailTo.pm
lib/App/ZofCMS/Plugin/AutoDump.pm
# HOW DOES IT WORK
There is a single `index.pl` script. The page to display is specified
via `page` query parameter (it can come from either POST or GET requests).
There is also a `dir` parameter, but it's use it optional. For example,
if you are to access `index.pl?page=foo/bar/baz/page` framework will
convert the query into `page=page&dir=foo/bar/baz/`.
The "config file" (see [App::ZofCMS::Config](https://metacpan.org/pod/App::ZofCMS::Config)) is loaded and checked whether
or not the specified page is an "allowed page"; if it isn't, user will
be presented with a 404.
Later on, the "ZofCMS template" file is located and loaded. This template
is just a file with a Perl hashref in it. All keys have special meanings,
see [App::ZofCMS::Template](https://metacpan.org/pod/App::ZofCMS::Template) for details. Some (or even all) of those keys
can be specified in the "config file" under several keys which provide
"defaults", see [App::ZofCMS::Config](https://metacpan.org/pod/App::ZofCMS::Config) for details.
ZofCMS template will reference a "base" template (which is a
[HTML::Template](https://metacpan.org/pod/HTML::Template) template) as well as several other [HTML::Template](https://metacpan.org/pod/HTML::Template)
files. The framework then will run any plugins, fill out all the values
templates - here is where you would put your ZofCMS templates.
ZofCMS - this is where ZofCMS "core", its plugins and
any "template exec modules" (more on that later)
will live.
In the `data` directory you will notice a file called `base.tmpl` this
is the "base" [HTML::Template](https://metacpan.org/pod/HTML::Template) file, it will be filled with virtually
all the keys from ZofCMS template. In the `templates` directory you will
find `index.tmpl` and `404.tmpl`
**Before we proceed any further** I advise you to read documentation
for [App::ZofCMS::Config](https://metacpan.org/pod/App::ZofCMS::Config) and [App::ZofCMS::Template](https://metacpan.org/pod/App::ZofCMS::Template) as I am not going
to explain what each key means; it is explained in aforementioned
documentation in detail.
## FIRST PAGE
Now, let's create our first page. Let it be named something original,
like "foo" :)
bin/zofcms_helper view on Meta::CPAN
END
close $fh_template;
}
}
}
}
exit
if $opts{nocore};
@opts{ qw/index base index_tmpl index_html_tmpl 404 config_file/ } = (
File::Spec->catfile( $opts{site}, 'index.pl' ),
File::Spec->catfile( $opts{core}, 'data', 'base.tmpl' ),
File::Spec->catfile( $opts{core}, 'templates', 'index.tmpl' ),
File::Spec->catfile( $opts{core}, 'data', 'index.tmpl' ),
File::Spec->catfile( $opts{core}, 'templates', '404.tmpl' ),
File::Spec->catfile( $opts{core}, 'config.txt' ),
);
open my $fh, '>', $opts{index}
or die "Failed to open/create $opts{index} [$!]";
print $fh make_index_pl( $opts{core} );
close $fh;
chmod 0755, $opts{index};
bin/zofcms_helper view on Meta::CPAN
print $fh make_index_tmpl();
open $fh, '>', $opts{index_html_tmpl}
or die "Failed to open/create $opts{index_html_tmpl} [$!]";
print $fh make_index_html_tmpl();
open $fh, '>', $opts{404}
or die "Failed to open/create $opts{404} [$!]";
print $fh make_404();
open $fh, '>', $opts{config_file}
or die "Failed to open/create $opts{config_file} [$!]";
print $fh make_config_file( $opts{core} );
copy_module( $_, $opts{core} )
for qw/
bin/zofcms_helper view on Meta::CPAN
body => \'index.tmpl',
title => '',
}
END_CODE
}
sub make_index_html_tmpl {
return 'Fill me up!'
}
sub make_404 {
return <<'END_CODE';
{
body => \'404.tmpl',
title => '404 - Page Not Found',
}
END_CODE
}
sub make_config_file {
my $core_dir = shift;
return <<"END_CONFIG";
use strict;
use warnings;
bin/zofcms_helper view on Meta::CPAN
zofcms_helper --site example --core example_core
The C<--core> argument specifies the name of directory for the "data"
directory of ZofCMS, in other words, this is web-inaccessible directory
in which you will have your config file, "data_storage" and "templates"
directory (see L<App::ZofCMS::Config> for description) as well as
any of ZofCMS plugins. The helper script creates config file, all of those
directories as well as directory C<Execs> (see L<App::ZofCMS::Template>)
and C<Extras> (see L<App::ZofCMS::Extras>). The helper script also creates
basic C<base.tmpl>, C<index.tmpl> and C<404.tmpl> in C<data/> directory
inside the directory specified by C<--core> as well as basic
C<index.tmpl> inside C<templates/> directory. If C<--core> parameter is not
specified it will be created by appending C<_site> to whatever you've
gave to C<--site> argument.
B<Note:> currently there is no support [in the helper script]
to have C<--core> point to a directory on a different level than C<--site>.
If you desperatelly need this please let me know and I will add that
support. For now, you can simply edit the created C<index.pl> file, in
particular it's two lines:
examples/templates/404.tmpl view on Meta::CPAN
{
body => q|<p>The page you've tried to access does not exist or was moved</p>|,
title => '404 - Page Not Found',
}
lib/App/ZofCMS.pm view on Meta::CPAN
=head1 HOW DOES IT WORK
There is a single C<index.pl> script. The page to display is specified
via C<page> query parameter (it can come from either POST or GET requests).
There is also a C<dir> parameter, but it's use it optional. For example,
if you are to access C<index.pl?page=foo/bar/baz/page> framework will
convert the query into C<page=page&dir=foo/bar/baz/>.
The "config file" (see L<App::ZofCMS::Config>) is loaded and checked whether
or not the specified page is an "allowed page"; if it isn't, user will
be presented with a 404.
Later on, the "ZofCMS template" file is located and loaded. This template
is just a file with a Perl hashref in it. All keys have special meanings,
see L<App::ZofCMS::Template> for details. Some (or even all) of those keys
can be specified in the "config file" under several keys which provide
"defaults", see L<App::ZofCMS::Config> for details.
ZofCMS template will reference a "base" template (which is a
L<HTML::Template> template) as well as several other L<HTML::Template>
files. The framework then will run any plugins, fill out all the values
lib/App/ZofCMS.pm view on Meta::CPAN
templates - here is where you would put your ZofCMS templates.
ZofCMS - this is where ZofCMS "core", its plugins and
any "template exec modules" (more on that later)
will live.
In the C<data> directory you will notice a file called C<base.tmpl> this
is the "base" L<HTML::Template> file, it will be filled with virtually
all the keys from ZofCMS template. In the C<templates> directory you will
find C<index.tmpl> and C<404.tmpl>
B<Before we proceed any further> I advise you to read documentation
for L<App::ZofCMS::Config> and L<App::ZofCMS::Template> as I am not going
to explain what each key means; it is explained in aforementioned
documentation in detail.
=head2 FIRST PAGE
Now, let's create our first page. Let it be named something original,
like "foo" :)
lib/App/ZofCMS/Config.pm view on Meta::CPAN
or $conf->{zcms_template_extension} = '.tmpl';
unless ( $no_page_check ) {
my $query = $self->query;
my $is_valid_page = $self->_is_valid_page(
$query,
$conf,
);
unless ( $is_valid_page ) {
@$query{ qw/page dir/ } = qw|404 /|;
}
}
return $self->conf( $conf );
}
sub _is_valid_page {
my ( $self, $query, $conf ) = @_;
my ( $ext, $templates_dir, $valid_pages )
lib/App/ZofCMS/Config.pm view on Meta::CPAN
'/',
'/tools/',
'/tools/ZofCMS/',
],
},
}
The C<valid_pages> specify which particular pages are available on your
site. If the page provided to C<index.pl> via C<page> and (optionally)
C<dir> parameter does not match C<valid_page> the user will be presented
with a 404 - Not Found page. The C<valid_pages> value is a hashref with
two keys each of which takes an arrayref as an argument; they are explained
a little further below, but first:
=head3 Note on C<page> and C<dir> query parameters
Which page to display in ZofCMS is determined by two query parameters:
C<page> and C<dir>. They are calculated in the following passion:
If C<page> query parameter is not specified it will default to
'index', if C<dir> query parameter is not specified it will default to
lib/App/ZofCMS/Config.pm view on Meta::CPAN
'/',
'/tools/',
'/tools/ZofCMS/',
],
The check for valid pages using C<dirs> arrayref is a bit different and
serves as a shortcut of some sort. What is done with the elements in
C<dirs> arrayref is ZofCMS makes a path and a filename in the following
form: $templates_dir (see above) + $dir_param (query parameter C<dir>)
+ $page_param (query parameter C<page>) + C<'.tmpl'> then it checks
if that file exists; if it doesn't - user is presented with 404.
Let's make this information into an example. Let's assume that you have set
your "templates dir" to
C<../zcms_site/templates/>, you didn't set anything for C<pages> key in
C<valid_pages> in your configuration file but you've set
C<< dirs => [ '/tools/' ] >> for C<valid_pages>. On top of all that,
you have created a file C<../zcms_site/templates/tools/stuff.tmpl> which
is the only file in that directory.
If user would go to C<http://example.com/index.pl?page=tools/stuff>,
ZofCMS would interpret C<../zcms_site/templates/tools/stuff.tmpl> template
and display a page, any other pages would give him a 404.
B<Note:> directories specified in C<dirs> arrayref are not recursable, i.e.
specifying C<< dirs => [ '/' ] >> enable pages in '/tools/'. Later, a
special flag to indicate recursing may be implemented.
=head2 C<template_defaults>
{
template_defaults => {
foo => 'bar',
lib/App/ZofCMS/Output.pm view on Meta::CPAN
my $self = bless {}, $class;
$self->config( $config );
$self->conf( $config->conf );
$self->template( $template );
return $self;
}
sub headers {
my $self = shift;
my $query = $self->config->query;
if ( $query->{dir} eq '/' and $query->{page} eq '404' ) {
return $self->config->cgi->header('text/html','404 Not Found');
}
return $self->config->cgi->header( -type => 'text/html', -charset => 'utf-8' );
}
sub output {
my $self = shift;
return $self->template->html_template->output;
}
( run in 3.242 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )