#!/usr/bin/env perl use 5.10.1; use strict; use warnings; use File::Basename qw(basename dirname); use File::Spec::Functions qw(catdir rel2abs); BEGIN { require lib; my $dir = rel2abs( dirname(__FILE__) ); lib->import( $dir, catdir( $dir, 'lib' ), catdir( $dir, qw(local lib perl5) ) ); } use Mojolicious::Lite; use Bugzilla::Constants; use Bugzilla::CGI::Mojo; use Try::Tiny; plugin 'PODRenderer'; app->renderer->add_handler( 'bugzilla' => sub { my ( $renderer, $c, $output, $options ) = @_; my %params; # Helpers foreach my $method ( grep {m/^\w+\z/} keys %{ $renderer->helpers } ) { my $sub = $renderer->helpers->{$method}; $params{$method} = sub { $c->$sub(@_) }; } # Stash values $params{$_} = $c->stash->{$_} for grep {m/^\w+\z/} keys %{ $c->stash }; $params{self} = $params{c} = $c; Bugzilla->template->process( $options->{template}, \%params, $output ) or die Bugzilla->template->error; } ); app->hook( around_dispatch => sub { my ($next, $c) = @_; try { local %{ Bugzilla->request_cache } = (); Bugzilla->usage_mode(USAGE_MODE_MOJO); Bugzilla->cgi( Bugzilla::CGI::Mojo->new(controller => $c) ); $next->(); } catch { die $_ unless /\bModPerl::Util::exit\b/; }; } ); get '/' => sub { my $c = shift; my $user = Bugzilla->login(LOGIN_OPTIONAL); $c->stash->{use_login_page} = 1; $c->render( template => 'index.html.tmpl', handler => 'bugzilla', user => $user ); }; app->start; __DATA__ @@ index.html.ep % layout 'default'; % title 'Welcome'; % use Bugzilla::Util qw(remote_ip);

Hello, <%= $user->name %> <<%= $user->email %>>

Your ip is <%= remote_ip() %>

@@ layouts/default.html.ep <%= title %> <%= content %>