++ed by:
Jan Henning Thorsen

NAME

Mojolicious::Plugin::UrlWith - Preserve parts of the url

VERSION

0.0502

DESCRIPTION

This helper provides the same method as "url_for" in Mojolicious::Controller with the difference that it keeps the query string.

SYNOPSIS

    package MyApp;
    sub startup {
        my $self = shift;

        $self->plugin('Mojolicious::Plugin::UrlWith' => {
            parse_fragment => 1,
            current_page_class => 'current-page',
        });

        # ...
    }

ATTRIBUTES

parse_fragment

Will remove the '#fragment' part from the first arugment to "url_with", and use it use it for "fragment" in Mojo::URL.

current_page_class

    $self->current_page_class($classname);
    $classname = $self->current_page_class;

Will add the $classname to the link in "link_with" if the path part of the link match the currently requested path. You need to set this attribute when registering the plugin, since the default value is empty string, cancelling the behavior.

This attribute is EXPERIMENTAL and may be removed/changed without warning.

HELPERS

url_with

The examples below has this current request url: http://somedomain.com/search?page=1.

$controller->url_with({ name => 'bob' });

Will result in http://somedomain.com/search?page=1&name=bob.

$controller->url_with({ page => undef });

Will result in http://somedomain.com/search.

$controller->url_with('named', { age => 42 });

Will result in http://somedomain.com/some/named/route?page=1&age=42.

$controller->url_with('/path', { random => 24 });

Will result in http://somedomain.com/path?page=1&random=24.

$controller->url_with('/path', [ c => 313 ]);

Will result in http://somedomain.com/path?c=313.

Summary: A hash-ref will be merged with existing query params, while an array-ref will create a new set of query params.

Same as "link_to" in Mojolicious::Plugin::TagHelpers, but use "url_with" instead of "url_to" in Mojolicious::Controller to construct the hyper reference.

METHODS

register

Will register the methods under "HELPERS".

COPYRIGHT & LICENSE

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Jan Henning Thorsen




Hosting generously
sponsored by Bytemark