Dancer

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

 - Markdownify the README. (GH#986, Chris Seymour)

1.3123 2014-04-12
 [BUG FIXES]
 - Test was skipping wrong number of tests if JSON was absent.

1.3122 2014-04-10
 [BUG FIXES]
 - Serializer::Mutable now consider 'Accept' before 'Content-Type'.
   (GH#996, Bernhard Reutner-Fischer)
 - Serializer::Mutable now correctly deals with content-types with
   charsets. (GH#996, Bernhard Reutner-Fischer)
 - Without Clone(), Dancer::Error::dumper() could clobber values in deep
   structures. (GH#1006, fix by asergei)
 - 'session_name' in Dancer::Session::Abstract couldn't be redefined.
   (GH#1004, patch by Lee Carmichael)

 [DOCUMENTATION]
 - GH #995: Documentation improvements. (Colin Kuskie)

 [MISC]

Changes  view on Meta::CPAN

 - GH #422: Documenting no need for caret when you have a prefix. (Sawyer
   X)

 [ENHANCEMENTS]
 - GH #396: Test that Dancer::Session::Cookie isn't broken (Michael G.
   Schwern)
 - GH #399: Make sure session can have their name changed. (Michael G.
   Schwern)
 - Dancer::Test tests assumes 'GET' if their first argument is scalar.
   (Yanick Champoux)
 - send_file accepts optional content-type declaration, to override guessed
   MIME type, e.g. send_file $filename, content_type => 'image/png'
   (Alberto Simões, requested by Michael G Schwern)
 - send_file accepts optional absolute option, to send an absolute path
   (Alberto Simões)
 - Have `dancer` cmd tool create MANIFEST and MANIFEST.SKIP. (Alberto
   Simões)
 - mime_type is deprecated; new keyword 'mime'; new config key
   'default_mime_type'; (Alberto Simões and Michael G. Schwern)
 - Recognize absolute redirects  (Yanick Champoux)

Changes  view on Meta::CPAN

1.3012 2011-03-01
 [BUG FIXES]
 - Fix cookies disappearing when more than one is set. Complete refactoring
   of the cookie handling. (Chris Andrews, Geistteufel)
 - Properly set the settings in Dancer::Test only after config loading.
   (Sawyer X)
 - Fix possible loss of last directory in path. (Sawyer X)
 - No need for default upper directory in Dancer::Test. This fixes an issue
   raised on the list about the default scaffolded test failing. (Sawyer X)
 - Fix anti UNC substitution under Cygwin (Rowan Thorpe)
 - GH#299 Return appropriate headers on HEAD request (content-type, ...)
   (franck cuny)
 - Use the dancer_version variable in scaffolded app. (Sawyer X, reported
   by Brian E. Lozier)

 [DOCUMENTATION]
 - Add missing methods (e.g. "referer"), sorting, clean up. (Flavio
   Poletti)
 - Complete working example of deployment under Nginx/Starman in
   Deployment.pod (Geistteufel)

Changes  view on Meta::CPAN

 [Damien Krotkine]
 - FIX for issue GH#115 documentation about compression in
   Dancer::Deployment

 [David Precious]
 - Make the 'layout' param to the template keyword work as you'd expect and
   allow you to set a custom layout to use, e.g.: template 'templatename',
   {}, { layout => 'layoutname' };

 [Franck Cuny]
 - FIX for issue GH#129 don't add multiple content-type to headers
 - fix broken tests (they were testing incorrect content type)

 [Naveed Massjouni]
 - Dancer::Test function get_response is renamed to dancer_response
   get_response still works but is deprecated
 - dispatch.f?cgi scripts use FindBin to resolve their location. FIX a bug
   when using symlinks.

 [Philippe Bruhat]
 - Make sure a plugin refuse to register a keyword twice

README  view on Meta::CPAN

 config

    Accesses the configuration of the application:

        get '/appname' => sub {
            return "This is " . config->{appname};
        };

 content_type

    Sets the content-type rendered, for the current route handler:

        get '/cat/:txtfile' => sub {
            content_type 'text/plain';
    
            # here we can dump the contents of param('txtfile')
        };

    You can use abbreviations for content types. For instance:

        get '/svg/:id' => sub {
            content_type 'svg';
    
            # here we can dump the image with id param('id')
        };

    Note that if you want to change the default content-type for every
    route, you have to change the content_type setting instead.

 dance

    Alias for the start keyword.

 dancer_version

    Returns the version of Dancer. If you need the major version, do
    something like:

README  view on Meta::CPAN

    (default being 42K bytes) using bytes:

        get '/download/:file' => sub {
            send_file(
                params->{file},
                streaming => 1,
                bytes     => 524288, # 512K
            );
        };

    The content-type will be set depending on the current MIME types
    definition (see mime if you want to define your own).

    If your filename does not have an extension, or you need to force a
    specific mime type, you can pass it to send_file as follows:

        send_file(params->{file}, content_type => 'image/png');

    Also, you can use your aliases or file extension names on content_type,
    like this:

lib/Dancer.pm  view on Meta::CPAN

=head2 config

Accesses the configuration of the application:

    get '/appname' => sub {
        return "This is " . config->{appname};
    };

=head2 content_type

Sets the B<content-type> rendered, for the current route handler:

    get '/cat/:txtfile' => sub {
        content_type 'text/plain';

        # here we can dump the contents of param('txtfile')
    };

You can use abbreviations for content types. For instance:

    get '/svg/:id' => sub {
        content_type 'svg';

        # here we can dump the image with id param('id')
    };

Note that if you want to change the default content-type for every route, you
have to change the C<content_type> setting instead.

=head2 dance

Alias for the C<start> keyword.

=head2 dancer_version

Returns the version of Dancer. If you need the major version, do something like:

lib/Dancer.pm  view on Meta::CPAN

42K bytes) using C<bytes>:

    get '/download/:file' => sub {
        send_file(
            params->{file},
            streaming => 1,
            bytes     => 524288, # 512K
        );
    };

The content-type will be set depending on the current MIME types definition
(see C<mime> if you want to define your own).

If your filename does not have an extension, or you need to force a
specific mime type, you can pass it to C<send_file> as follows:

    send_file(params->{file}, content_type => 'image/png');

Also, you can use your aliases or file extension names on
C<content_type>, like this:

lib/Dancer/Plugin/Ajax.pm  view on Meta::CPAN

Disable the layout

=item *

The action built matches POST / GET requests.

=back

=head1 CONFIGURATION

By default the plugin will use a content-type of 'text/xml' but this can be overwritten
with plugin setting 'content_type'.

Here is example to use JSON:

  plugins:
    'Ajax':
      content_type: 'application/json'

=head1 AUTHOR

lib/Dancer/Serializer.pm  view on Meta::CPAN

        else {
            $response->header('Content-Type' => engine->content_type);
            $response->{content} = $content;
        }
    }

    return $response;
}

# deserialize input params in the request body, if matching the Serializer's
# content-type.
sub process_request {
    my ($class, $request) = @_;

    Dancer::Factory::Hook->execute_hooks('before_deserializer');

    return $request unless engine;

    # Content-Type may contain additional parameters
    # (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7)
    # which should be safe to ignore at this level.

lib/Dancer/Serializer/Mutable.pm  view on Meta::CPAN

=item

the B<accept> from the request headers

=item

The default is B<application/json>

=back

The content-type/serializer mapping that C<Dancer::Serializer::Mutable>
uses is

    serializer               | content types
    ----------------------------------------------------------
    Dancer::Serializer::YAML | text/x-yaml, text/html
    Dancer::Serializer::XML  | text/xml
    Dancer::Serializer::JSON | text/x-json, application/json

=head1 EXPORTABLE FUNCTIONS

=head2 template_or_serialize( $template, $data, $options )

For instances where you want to render a template for normal browser requests,
and return serialized content for AJAX calls. 

If the requested content-type is I<text/html>, C<template_or_serialize>
returns the rendered template, else it returns I<$data> unmodified 
(which will then be serialized as usual).

C<template_or_serialize> is not exported by default.

    use Dancer::Serializer::Mutable qw/ template_or_serialize /;

    get '/greetings' => sub {
        ...;

lib/Dancer/Serializer/Mutable.pm  view on Meta::CPAN


=head2 serialize

Serialize a data structure. The format it is serialized to is determined
automatically as described above. It can be one of YAML, XML, JSON, defaulting
to JSON if there's no clear preference from the request.

=head2 deserialize

Deserialize the provided serialized data to a data structure.  The type of 
serialization format depends on the request's content-type. For now, it can 
be one of YAML, XML, JSON.

=head2 content_type

Returns the content-type that was used during the last C<serialize> /
C<deserialize> call. B<WARNING> : you must call C<serialize> / C<deserialize>
before calling C<content_type>. Otherwise the return value will be C<undef>.

=head1 AUTHOR

Dancer Core Developers

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Alexis Sukrieh.

t/02_request/15_headers.t  view on Meta::CPAN

    client => sub {
        my $port = shift;
        my $ua = HTTP::Tiny::NoProxy->new;

        my $headers = { 'X-User-Head1' => 42, 'X-User-Head2' => 43 };

        my $res = $ua->get("http://127.0.0.1:$port/req", { headers => $headers });
        ok($res->{success}, "$handler server responded");
        is($res->{headers}{'x-foo'}, 2);
        is($res->{headers}{'x-bar'}, 3);
        is($res->{headers}{'content-type'}, 'text/plain');
    },
    server => sub {
        my $port = shift;
        use Dancer;

        set( apphandler   => $handler,
             port         => $port,
             server       => '127.0.0.1',
             show_errors  => 1,
             startup_info => 0 );

t/03_route_handler/03_routes_api.t  view on Meta::CPAN

setting 'public' => 't/03_route_handler/public';

my $r5 = Dancer::Route->new(
    method  => 'get',
    pattern => '/error',
    code    => sub { send_error( "no", 404 ) }
);
$req = Dancer::Request->new_for_request( GET => '/error' );
my $res = $r5->run($req);
is( ( grep { /Content-Type/ } @{ $res->headers_to_array } ),
    1, 'only one content-type' );

t/03_route_handler/21_ajax.t  view on Meta::CPAN

        foreach my $query (@queries) {
            my %headers;
            $headers{'X-Requested-With'} = 'XMLHttpRequest'
              if ( $query->{ajax} == 1);

            ok my $res = $ua->get("http://127.0.0.1:$port/" . $query->{path}, { headers => \%headers });

            if ( $query->{success} == 1) {
                ok $res->{success};
                is $res->{content}, $query->{content};
                like $res->{headers}{'content-type'}, qr/text\/xml/ if $query->{ajax} == 1;
            }
            else {
                ok !$res->{success};
            }
        }

        # test ajax with content_type to json
        my %headers = ( 'X-Requested-With' => 'XMLHttpRequest' );
        ok my $res = $ua->get("http://127.0.0.1:$port/ajax.json", { headers => \%headers });
        like $res->{headers}{'content-type'}, qr/json/;
    },
    server => sub {
        my $port = shift;

        use Dancer;
        use Dancer::Plugin::Ajax;

        set startup_info => 0, port => $port, server => '127.0.0.1', layout => 'wibble';

        ajax '/req' => sub {



( run in 0.820 second using v1.01-cache-2.11-cpan-524268b4103 )