| 1 | package CBOR::Free::SequenceDecoder; | ||
| 2 | |||
| 3 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 6 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | =encoding utf-8 | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | CBOR::Free::SequenceDecoder | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | my $decoder = CBOR::Free::SequenceDecoder->new(); | ||
| 15 | |||
| 16 | if ( my $got_sr = $decoder->give( $some_cbor ) ) { | ||
| 17 | |||
| 18 | # Do something with your decoded CBOR. | ||
| 19 | } | ||
| 20 | |||
| 21 | while (my $got_sr = $decoder->get()) { | ||
| 22 | # Do something with your decoded CBOR. | ||
| 23 | } | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | This module implements a parser for CBOR Sequences | ||
| 28 | (L<RFC 8742|https://tools.ietf.org/html/rfc8742>). | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | #---------------------------------------------------------------------- | ||
| 33 | |||
| 34 | 6 | ▶ | use parent qw( CBOR::Free::Decoder::Base ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 35 | |||
| 36 | 6 | ▶ | use CBOR::Free; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 37 | |||
| 38 | #---------------------------------------------------------------------- | ||
| 39 | |||
| 40 | =head1 METHODS | ||
| 41 | |||
| 42 | This module implements the following methods in common | ||
| 43 | with L<CBOR::Free::Decoder>: | ||
| 44 | |||
| 45 | =over | ||
| 46 | |||
| 47 | =item * C<new()> | ||
| 48 | |||
| 49 | =item * C<preserve_references()> | ||
| 50 | |||
| 51 | =item * C<naive_utf8()> | ||
| 52 | |||
| 53 | =item * C<reject_duplicate_keys()> | ||
| 54 | |||
| 55 | =item * C<string_decode_cbor()> | ||
| 56 | |||
| 57 | =item * C<string_decode_never()> | ||
| 58 | |||
| 59 | =item * C<string_decode_always()> | ||
| 60 | |||
| 61 | =item * C<set_tag_handlers()> | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | Additionally, the following exist: | ||
| 66 | |||
| 67 | =head2 $got_sr = I<CLASS>->give( $CBOR ); | ||
| 68 | |||
| 69 | Adds some bytes ($CBOR) to the decoder’s internal CBOR buffer. | ||
| 70 | Returns either: | ||
| 71 | |||
| 72 | =over | ||
| 73 | |||
| 74 | =item * a B<scalar reference> to the (parsed) first CBOR document in the | ||
| 75 | internal buffer | ||
| 76 | |||
| 77 | =item * undef, if there is no such document | ||
| 78 | |||
| 79 | =back | ||
| 80 | |||
| 81 | Note that if your decoded CBOR document’s root element is already a reference | ||
| 82 | (e.g., an array or hash reference), then the return value is a reference | ||
| 83 | B<to> that reference. So, for example, if you expect all documents in your | ||
| 84 | stream to be array references, you could do: | ||
| 85 | |||
| 86 | if ( my $got_sr = $decoder->give( $some_cbor ) ) { | ||
| 87 | my @decoded_array = @{ $$got_sr }; | ||
| 88 | |||
| 89 | # … | ||
| 90 | } | ||
| 91 | |||
| 92 | =head2 $got_sr = I<CLASS>->get(); | ||
| 93 | |||
| 94 | Like C<give()> but doesn’t append onto the internal CBOR buffer. | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | 6 | 1; | |