::Types->new;
$mimes->addType(
MIME::Type->new(
type => 'text/x-json',
extensions => [qw/json/]
)
);
$mimes->addType(
MIME::Type->new(
type => 'text/x-y
>mimeTypeOf('rss');
}
sub wants_json {
my $self = shift;
my $c = $self->context;
return $c->request->preferred_content_type eq $mimes->mimeTypeOf('json');
}
sub wants_yaml {
my $
id($id);
$c->stash->{'entity'} = $user;
};
http://localhost/user/1?view=json
=head1 DESCRIPTION
Mango::Catalyst::Controller::REST is a base Catalyst controller that
automat
rical type: '$type'";
}
return $class->SUPER::new(value => $value, type => $type);
}
sub TO_JSON { 0 + shift->value }
sub to_string { '' . shift->value }
sub isa_number {
my $value = shift;
e given type. The 3 supported types are C<DOUBLE>,
C<INT32> and C<INT64>.
=head2 TO_JSON
my $num = $obj->TO_JSON;
Return the numerical value.
=head2 to_string
my $str = $num->to_string;
Retu
> sub { shift->data }, fallback => 1;
use Mojo::Util 'b64_encode';
has [qw(data type)];
sub TO_JSON { b64_encode shift->data, '' }
1;
=encoding utf8
=head1 NAME
Mango::BSON::Binary - Binary typ
container for the BSON binary type used by
L<Mango::BSON>. For C<JSON> implementations like L<Mojo::JSON>, that support
the C<TO_JSON> method, it will automatically C<Base64> encode the binary data.
its all methods from L<Mojo::Base> and implements
the following new ones.
=head2 TO_JSON
my $b64 = $bin->TO_JSON;
Base64 encode L</"data">.
=head1 OPERATORS
L<Mango::BSON::Binary> overloads the
use Time::HiRes 'time';
sub new { shift->SUPER::new(time => shift // int(time * 1000)) }
sub TO_JSON { 0 + shift->{time} }
sub to_datetime { Mojo::Date->new->epoch(shift->to_epoch)->to_datetime }
N::Time->new(time * 1000);
Construct a new L<Mango::BSON::Time> object.
=head2 TO_JSON
my $num = $time->TO_JSON;
Numeric representation of time.
=head2 to_datetime
my $str = $time->to_dateti
::Number;
use Mango::BSON::ObjectID;
use Mango::BSON::Time;
use Mango::BSON::Timestamp;
use Mojo::JSON;
use Scalar::Util 'blessed';
my @BSON = (
qw(bson_bin bson_code bson_dbref bson_decode bson_do
32() => 'l<',
INT64() => 'q<'
);
# Reuse boolean singletons
my $FALSE = Mojo::JSON->false;
my $TRUE = Mojo::JSON->true;
my $BOOL = blessed $TRUE;
my $MAXKEY = bless {}, 'Mango::BSON::_MaxKey';
ck_fmt{$t}, $value->value);
}
# Blessed reference with TO_JSON method
if (my $sub = $value->can('TO_BSON') // $value->can('TO_JSON')) {
return _encode_value($e, $value->$sub);
}
# Stri