File: MultiFormToken.pm

package info (click to toggle)
libcatalyst-controller-html-formfu-perl 2.04-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 408 kB
  • sloc: perl: 960; makefile: 6
file content (56 lines) | stat: -rw-r--r-- 1,485 bytes parent folder | download | duplicates (3)
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
package TestApp::Controller::MultiFormToken;

use strict;
use warnings;
use base 'Catalyst::Controller::HTML::FormFu';

__PACKAGE__->config( { 'Controller::HTML::FormFu' => { request_token_enable => 1 } } );

sub multiformtoken : Chained : CaptureArgs(0) {
    my ( $self, $c ) = @_;

    $c->stash->{template} = 'multiform.tt';
}

sub formconfig : Chained('multiformtoken') : Args(0) : MultiFormConfig('multiform/formconfig') {
    my ( $self, $c ) = @_;

    my $multi = $c->stash->{multiform};
    $multi->action('/multiformtoken/formconfig');
    if ( $multi->complete ) {
        my $params = $multi->current_form->params;

        $c->stash->{results} = join "\n", map { sprintf "%s: %s", $_, $params->{$_} } keys %$params;

        $c->stash->{message} = 'Complete';
    }
}

sub file_upload : Chained('multiformtoken') : Args(0) : MultiFormConfig {
    my ( $self, $c ) = @_;

    my $multi = $c->stash->{multiform};

    if ( $multi->complete ) {
        my $params = $multi->current_form->params;

        $c->stash->{results} = '';

        for ( keys %$params ) {
            my $upload = $params->{$_};

            my $size     = $upload->size;
            my $length   = length $upload->slurp;
            my $filename = $upload->filename;
            my $type     = $upload->type;

            $c->stash->{results} .= <<END;
param: $_, size: $size, length: $length, filename: $filename, type: $type
END
        }

        $c->stash->{message} = 'Complete';
    }
}

1;