File: URI.pm

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (104 lines) | stat: -rw-r--r-- 2,659 bytes parent folder | download | duplicates (4)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package TestApp::Controller::Engine::Request::URI;

use strict;
use base 'Catalyst::Controller';

sub default : Private {
    my ( $self, $c ) = @_;

    $c->forward('TestApp::View::Dump::Request');
}

sub change_path : Local {
    my ( $self, $c ) = @_;

    # change the path
    $c->req->path( '/my/app/lives/here' );

    $c->forward('TestApp::View::Dump::Request');
}

sub change_base : Local {
    my ( $self, $c ) = @_;

    # change the base and uri paths
    $c->req->base->path( '/new/location' );
    $c->req->uri->path( '/new/location/engine/request/uri/change_base' );

    $c->forward('TestApp::View::Dump::Request');
}

sub uri_with : Local {
    my ( $self, $c ) = @_;

    # change the current uri
    my $uri   = $c->req->uri_with( { b => 1, c => undef } );
    my %query = $uri->query_form;

    $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
    $c->res->header( 'X-Catalyst-Param-b' => $query{ b } );
    $c->res->header( 'X-Catalyst-Param-c' => exists($query{ c }) ? $query{ c } : '--notexists--' );
    $c->res->header( 'X-Catalyst-query' => $uri->query);

    $c->forward('TestApp::View::Dump::Request');
}

sub uri_with_object : Local {
    my ( $self, $c ) = @_;

    my $uri   = $c->req->uri_with( { a => $c->req->base } );
    my %query = $uri->query_form;

    $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );

    $c->forward('TestApp::View::Dump::Request');
}

sub uri_with_utf8 : Local {
    my ( $self, $c ) = @_;

    # change the current uri
    my $uri = $c->req->uri_with( { unicode => "\x{2620}" } );

    $c->res->header( 'X-Catalyst-uri-with' => "$uri" );

    $c->forward('TestApp::View::Dump::Request');
}

sub uri_with_undef : Local {
    my ( $self, $c ) = @_;

    my $warnings = 0;
    local $SIG{__WARN__} = sub { $warnings++ };

    # change the current uri
    my $uri = $c->req->uri_with( { foo => undef } );

    $c->res->header( 'X-Catalyst-warnings' => $warnings );

    $c->forward('TestApp::View::Dump::Request');
}

sub uri_with_undef_only : Local {
    my ( $self, $c ) = @_;

    my $uri = $c->req->uri_with( { a => undef } );

    $c->res->header( 'X-Catalyst-uri-with' => "$uri" );
    $c->forward('TestApp::View::Dump::Request');
}

sub uri_with_undef_ignore : Local {
    my ( $self, $c ) = @_;

    my $uri = $c->req->uri_with( { a => 1, b => undef } );

    my %query = $uri->query_form;
    $c->res->header( 'X-Catalyst-uri-with' => "$uri" );
    $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
    $c->res->header( 'X-Catalyst-Param-b' => $query{ b } );
    $c->res->header( 'X-Catalyst-Param-c' => $query{ c } );
    $c->forward('TestApp::View::Dump::Request');
}

1;