File: Foo.pm

package info (click to toggle)
libmojolicious-perl 0.999926-1%2Bsqueeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,672 kB
  • ctags: 949
  • sloc: perl: 17,391; makefile: 4
file content (76 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright (C) 2008-2010, Sebastian Riedel.

package MojoliciousTest::Foo;

use strict;
use warnings;

use base 'Mojolicious::Controller';

# If you're programmed to jump off a bridge, would you do it?
# Let me check my program... Yep.
sub badtemplate { shift->render(template => 'badtemplate') }

sub config {
    my $self = shift;
    $self->render_text($self->stash('config')->{test});
}

sub exceptionduringpausedtransaction { shift->pause and die 'Exception' }

sub index {
    shift->stash(
        layout  => 'default',
        handler => 'xpl',
        msg     => 'Hello World!'
    );
}

sub session_domain {
    my $self = shift;
    $self->session(user => 'Bender');
    $self->render_text('Bender rockzzz!');
}

sub something {
    my $self = shift;
    $self->res->headers->header('X-Bender' => 'Bite my shiny metal ass!');
    $self->render_text($self->url_for('something', something => '42'));
}

sub stage1 {
    my $self = shift;

    # Authenticated
    return 1 if $self->req->headers->header('X-Pass');

    # Fail
    $self->render_text('Go away!');
    return;
}

sub stage2 { shift->render_text('Welcome aboard!') }

sub syntaxerror { shift->render('syntaxerror', format => 'html') }

sub templateless { shift->render(handler => 'test') }

sub test {
    my $self = shift;
    $self->res->headers->header('X-Bender' => 'Bite my shiny metal ass!');
    $self->render_text($self->url_for(controller => 'bar'));
}

sub url_for_missing {
    my $self = shift;
    $self->render_text(
        $self->url_for('something_missing', something => '42'));
}

sub willdie { die 'for some reason' }

sub withblock { shift->render(template => 'withblock') }

sub withlayout { shift->stash(template => 'withlayout') }

1;