| 1 | package Mojolicious::Plugin::CBOR; | ||
| 2 | |||
| 3 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use CBOR::XS; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | our $VERSION = '0.04'; | |
| 7 | |||
| 8 | sub register | ||
| 9 | 1 | ▶ | { |
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
documented
| |||
| 10 | 1 | my ($self, $app, $args) = @_; | |
| 11 | |||
| 12 | 1 | $app->types->type(cbor => 'application/cbor; charset=UTF-8'); | |
| 13 | |||
| 14 | 1 | ▶ | $app->renderer->add_handler(cbor => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 15 | 1 | my ($renderer, $c, $output, $options) = @_; | |
| 16 | |||
| 17 | # force disabling Mojo encoding | ||
| 18 | 1 | delete $options->{'encoding'}; | |
| 19 | |||
| 20 | 1 | $options->{'format'} = 'cbor'; | |
| 21 | |||
| 22 | 1 | my $cbor = CBOR::XS->new(); | |
| 23 | |||
| 24 | 1 | $$output = $cbor->encode($c->stash->{'cbor'}); | |
| 25 | 1 | }); | |
| 26 | } | ||
| 27 | |||
| 28 | 1 | 1; | |
| 29 | |||
| 30 | __END__ | ||