| 1 | use utf8; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | package DR::Tnt::Msgpack::Types; | ||
| 6 | use base 'Exporter'; | ||
| 7 | |||
| 8 | use DR::Tnt::Msgpack::Types::Int; | ||
| 9 | use DR::Tnt::Msgpack::Types::Str; | ||
| 10 | use DR::Tnt::Msgpack::Types::Blob; | ||
| 11 | use DR::Tnt::Msgpack::Types::Bool; | ||
| 12 | |||
| 13 | our %EXPORT_TAGS = ( | ||
| 14 | 'all' => [ | ||
| 15 | 'mp_int', | ||
| 16 | 'mp_bool', | ||
| 17 | 'mp_string', | ||
| 18 | 'mp_blob', | ||
| 19 | |||
| 20 | 'mp_true', | ||
| 21 | 'mp_false', | ||
| 22 | ] | ||
| 23 | ); | ||
| 24 | |||
| 25 | our @EXPORT_OK = @{ $EXPORT_TAGS{all} }; | ||
| 26 | |||
| 27 | |||
| 28 | sub mp_int($) { | ||
| 29 | DR::Tnt::Msgpack::Types::Int->new($_[0]); | ||
| 30 | } | ||
| 31 | sub mp_string($) { | ||
| 32 | DR::Tnt::Msgpack::Types::Str->new($_[0]); | ||
| 33 | } | ||
| 34 | sub mp_blob($) { | ||
| 35 | DR::Tnt::Msgpack::Types::Blob->new($_[0]); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub mp_bool($) { | ||
| 39 | DR::Tnt::Msgpack::Types::Bool->new($_[0]); | ||
| 40 | } | ||
| 41 | sub mp_true() { | ||
| 42 | DR::Tnt::Msgpack::Types::Bool->new(1); | ||
| 43 | } | ||
| 44 | sub mp_false() { | ||
| 45 | DR::Tnt::Msgpack::Types::Bool->new(0); | ||
| 46 | } | ||
| 47 | |||
| 48 | =head1 NAME | ||
| 49 | |||
| 50 | DR::Tnt::Msgpack::Types - types for msgpack. | ||
| 51 | |||
| 52 | =head1 SYNOPSIS | ||
| 53 | |||
| 54 | use DR::Tnt::Msgpack::Types; | ||
| 55 | |||
| 56 | # pack as msgpack INT | ||
| 57 | msgpack(mp_int(123)); | ||
| 58 | |||
| 59 | # pack number as string | ||
| 60 | msgpack(mp_string(123)); | ||
| 61 | |||
| 62 | # bools | ||
| 63 | msgpack(mp_true); | ||
| 64 | msgpack(mp_false); | ||
| 65 | msgpack(mp_bool(1)); | ||
| 66 | msgpack(mp_bool(0)); | ||
| 67 | |||
| 68 | |||
| 69 | # blob | ||
| 70 | msgpack(mp_blob $blob); | ||
| 71 | |||
| 72 | |||
| 73 | =head1 DESCRIPTION | ||
| 74 | |||
| 75 | Perl doesn't differ C<123> and C<'123'>: | ||
| 76 | |||
| 77 | msgpack(123); | ||
| 78 | msgpack('123'); # the same | ||
| 79 | |||
| 80 | From time to time You want to pack numbers as strings (for example You | ||
| 81 | use tarantool's STR-index for user's texts, that contain numbers, too). | ||
| 82 | |||
| 83 | So You can use C<mp_string($)> constructor for L<DR::Tnt::Msgpack::Types::Str>. | ||
| 84 | |||
| 85 | =head1 METHODS | ||
| 86 | |||
| 87 | =over | ||
| 88 | |||
| 89 | =item mp_int($) | ||
| 90 | |||
| 91 | Create L<DR::Tnt::Msgpack::Types::Int> object. Its method C<TO_MSGPACK> | ||
| 92 | packs number as msgpack signed integer value. | ||
| 93 | |||
| 94 | =item mp_string($) | ||
| 95 | |||
| 96 | Create L<DR::Tnt::Msgpack::Types::Str> object. Its method C<TO_MSGPACK> | ||
| 97 | packs perl scalar as msgpack string. | ||
| 98 | |||
| 99 | =item mp_blob($) | ||
| 100 | |||
| 101 | Create L<DR::Tnt::Msgpack::Types::Blob> object. Its method C<TO_MSGPACK> | ||
| 102 | packs perl scalar as msgpack bin object. | ||
| 103 | |||
| 104 | =item mp_bool($) and shortcuts mp_true/mp_false | ||
| 105 | |||
| 106 | Create L<DR::Tnt::Msgpack::Types::Bool> object. Its method C<TO_MSGPACK> | ||
| 107 | package perl scalar as msgpack boolean. | ||
| 108 | |||
| 109 | =back | ||
| 110 | |||
| 111 | =cut | ||
| 112 | 1; |