Bigtop

 view release on metacpan or  search on metacpan

lib/Bigtop/Backend/CGI/Gantry.pm  view on Meta::CPAN

        { keyword => 'flex_db',
          label   => 'Database Flexibility',
          descr   => 'Adds command line args to stand alone server to '
                        .   'allow easy DBD switching',
          type    => 'boolean',
          default => 'false', },

        { keyword => 'template',
          label   => 'Alternate Template',
          descr   => 'A custom TT template.',
          type    => 'text' },

    ];
}

sub gen_CGI {
    my $class        = shift;
    my $base_dir     = shift;
    my $tree         = shift;

    my $configs      = $tree->get_app_configs();
    my $fast_cgi     = $tree->get_config->{CGI}{fast_cgi} || 0;
    my $gantry_conf  = $tree->get_config->{CGI}{gantry_conf} || 0;

    my %cgi_conf_types;

    CGI_ONLY_CHECK:
    foreach my $conf_type ( keys %{ $configs } ) {
        $cgi_conf_types{ $conf_type } = 1 if ( $conf_type =~ /^CGI|CGI$/i );
    }

    my $there_is_a_cgi = keys %cgi_conf_types;

    CONF_TYPE:
    foreach my $conf_type ( keys %{ $configs } ) {
        my $content      = $class->output_cgi(
            {
                tree      => $tree,
                configs   => $configs,
                conf_type => $conf_type,
                fast_cgi  => $fast_cgi,
                base_dir  => $base_dir,
            }
        );

        my $write_cgi   = 1;
        my $file_type   = ( $conf_type eq 'base' ) ? '' : "$conf_type.";
        my $server_type = $file_type;

        if ( $there_is_a_cgi ) {
            $file_type = $conf_type;
            $write_cgi = 0 if ( $file_type !~ s/^CGI|CGI$// );
        }

        my $cgi_file  = File::Spec->catfile(
                $base_dir, "app.${file_type}cgi"
        );

        Bigtop::write_file( $cgi_file, $content->{ cgi } ) if $write_cgi;

        chmod 0755, $cgi_file;

        if ( $tree->get_config->{CGI}{with_server} ) {
            next CONF_TYPE if ( $gantry_conf and $conf_type ne 'base' );

            my $server_file  = File::Spec->catfile(
                    $base_dir,
                    "app.${server_type}server"
            );

            Bigtop::write_file( $server_file, $content->{ server } );

            chmod 0755, $server_file;
        }
    }
}

our $template_is_setup = 0;
our $default_template_text = <<'EO_TT_BLOCKS';
[% BLOCK cgi_script %]
#![% perl_path +%]
use strict;

[% literal %]

use CGI::Carp qw( fatalsToBrowser );

use [% app_name %] qw{
    -Engine=CGI
    -TemplateEngine=[% template_engine +%]
[% IF plugins %]    -PluginNamespace=[% app_name +%]
    [% plugins +%]
[% END %]
};

use Gantry::Engine::CGI;

my $cgi = Gantry::Engine::CGI->new( {
[% config %]
[% locs %]
} );

$cgi->dispatch();

if ( $cgi->{config}{debug} ) {
    foreach ( sort { $a cmp $b } keys %ENV ) {
        print "$_ $ENV{$_}<br />\n";
    }
}
[% END %][%# end of block cgi_script %]

[% BLOCK stand_alone_server %]
#![% perl_path +%]
use strict;

[% literal %]

use lib qw( lib );

use [% app_name %] qw{
    -Engine=CGI
    -TemplateEngine=[% template_engine +%]
    Static
[% IF plugins %]    -PluginNamespace=[% app_name +%]
    [% plugins +%]
[% END %]
};

[% IF flex_db %]
use Getopt::Long;
[% END %]
use Gantry::Server;
use Gantry::Engine::CGI;



( run in 0.886 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )