| 1 | |||||||||||
| 2 | package Net::OBEX::Packet::Headers::Unicode; | ||||||||||
| 3 | |||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 9 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 9 | ▶ | use Encode qw(encode_utf8); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 9 | ▶ | use base 'Net::OBEX::Packet::Headers::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 9 | our $VERSION = '1.001002'; # VERSION | |||||||||
| 13 | |||||||||||
| 14 | 9 | my %Header_HI_For = ( | |||||||||
| 15 | name => "\x01", | ||||||||||
| 16 | description => "\x05", | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||
| 20 | 2 | my ( $class, $name, $value ) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 2 | ▶ | croak "Missing header name or HI identifier" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | unless defined $name; | ||||||||||
| 24 | |||||||||||
| 25 | $name = $Header_HI_For{ lc $name } | ||||||||||
| 26 | 2 | ▶ | if exists $Header_HI_For{ lc $name }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 2 | ▶ | $value = '' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | unless defined $value; | ||||||||||
| 30 | |||||||||||
| 31 | 2 | return bless { | |||||||||
| 32 | value => $value, | ||||||||||
| 33 | hi => $name, | ||||||||||
| 34 | }, $class; | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 2 | ▶ | sub make { | ||||||||
|
Subroutine
make: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 38 | 2 | my $self = shift; | |||||||||
| 39 | |||||||||||
| 40 | 2 | my $value = $self->value; | |||||||||
| 41 | 2 | ▶ | unless ( length $value ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | return $self->hi . "\x00\x03"; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 2 | $value = pack 'n*', unpack 'U*', encode_utf8($value); | |||||||||
| 46 | |||||||||||
| 47 | 2 | my $header = $self->hi; # header code | |||||||||
| 48 | 2 | $header .= pack 'n', 4 + length $value; | |||||||||
| 49 | 2 | $header .= $value . "\x00"; | |||||||||
| 50 | 2 | return $self->header($header); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 9 | 1; | |||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||