File: Counter.pm

package info (click to toggle)
libmojomojo-perl 1.01%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,272 kB
  • ctags: 879
  • sloc: perl: 14,055; sh: 145; xml: 120; ruby: 6; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download | duplicates (5)
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
package MojoMojo::Extensions::Counter;

use strict;
use warnings;

use base qw(MojoMojo::Extension); # ISA Catalyst::Controller

=head1 Name

MojoMojo::Extensions::Counter - a page counter

=head2 Methods

=head2 index

View page.

=cut

sub index :Path('counter') :Args(0) {
    my ( $self, $c ) = @_;

    $c->detach('view');
}

=head2 view

Add count into the view.

=cut

sub view :Path('counter.view') :Args(0) {
    my ( $self, $c ) = @_;
    @{$c->stash}{qw(current_view template count)} = ('TT', 'extensions/counter.tt', $c->session->{count} || 0);
}

=head2 add

Increment count by 1.

=cut

sub add :Path('counter.add') :Args(0) {
    my ( $self, $c ) = @_;

    my $session = $c->session;
    my $count = $session->{count} || 0;
    $session->{count} = $count + 1;

    $c->res->redirect($c->uri_for('/special/counter'));
}

=head2 subtract

Reduce count by 1.

=cut

sub subtract :Path('counter.subtract') :Args(0) {
    my ( $self, $c ) = @_;

    my $session = $c->session;
    my $count = $session->{count} || 0;
    $session->{count} = $count - 1;

    $c->res->redirect($c->uri_for('/special/counter'));
}

1;