Skip to content

Document how write a Dancer2 CGI app #1679

Open
@toddr

Description

@toddr

I worked with @xsawyerx today and we figured out how to write a Dancer2 app in CGI. We feel like it should be documented but we're not sure where:

use Dancer2;
use Plack::Loader;
use Template::Provider::FromDATA;

# Tell Dancer to use the DATA section for templates                                                                                                                                                                                                                                                                                                                                                     
my $provider = Template::Provider::FromDATA->new( { CLASSES => __PACKAGE__ } );
set engines => {template => { template_toolkit => { LOAD_TEMPLATES => [ $provider ] }}};
set template => 'template_toolkit';

get '/' => sub {
    template 'mytemplate' => { bar => "foo" };
};
Plack::Loader->auto->run(main->to_app);

__DATA__                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                        
__mytemplate.tt__                                                                                                                                                                                                                                                                                                                                                                                       
Flib [% bar %]                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                                        
__anothertemplate.tt__                                                                                                                                                                                                                                                                                                                                                                                  
Something else here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions