Parse-WBXML

 view release on metacpan or  search on metacpan

lib/Parse/WBXML.pm  view on Meta::CPAN

package Parse::WBXML;
# ABSTRACT: Support for WBXML as defined by the Open Mobile Alliance specs
use strict;
use warnings;
use parent qw(Mixin::Event::Dispatch);
use Try::Tiny;

use I18N::Charset qw(mib_to_charset_name);
use Encode ();

our $VERSION = '0.005';

=head1 NAME

Parse::WBXML - event-driven support for the generation and parsing of WBXML documents

=head1 VERSION

version 0.005

=head1 SYNOPSIS

 use Parse::WBXML;
 my $wbxml = Parse::WBXML->new;
 $wbxml->add_handler_for_event(
   start_element => sub {
     my ($self, $el) = @_;
     $self;
   },
   characters => sub {
     my ($self, $data) = @_;
     $self;
   },
   end_element => sub {
     my ($self, $el) = @_;
     $self;
   },
 );
 $wbxml->parse("wbxml data");

=head1 DESCRIPTION

WARNING: this is an early alpha release, if you want WBXML support then please try
the other modules in L</SEE ALSO> first. The current API may change before the 1.0
release.

Provides a pure-Perl implementation for the WBXML compressed XML format.
Slower and less efficient than the libwbxml2-based alternatives (L</SEE ALSO>),
but supports streaming SAX-like parsing.

This may be of some use in low-bandwidth situations where you want data as soon
as available from the stream, or in cases where the document is damaged and you
want to recover as much data as possible, or if you just don't have libwbxml2
available.

=head1 METHODS

=cut

# From WAP-192-WBXML-20010725-a table 4, "Global tokens"
use constant {
	TOKEN_SWITCH_PAGE	=> 0x00,
	TOKEN_END		=> 0x01,
	TOKEN_ENTITY		=> 0x02,
	TOKEN_STR_I		=> 0x03,
	TOKEN_LITERAL		=> 0x04,
	TOKEN_EXT_I_0		=> 0x40,
	TOKEN_EXT_I_1		=> 0x41,
	TOKEN_EXT_I_2		=> 0x42,
	TOKEN_PI		=> 0x43,
	TOKEN_LITERAL_C		=> 0x44,
	TOKEN_EXT_T_0		=> 0x80,
	TOKEN_EXT_T_1		=> 0x81,
	TOKEN_EXT_T_2		=> 0x82,
	TOKEN_STR_T		=> 0x83,
	TOKEN_LITERAL_A		=> 0x84,
	TOKEN_EXT_0		=> 0xC0,
	TOKEN_EXT_1		=> 0xC1,
	TOKEN_EXT_2		=> 0xC2,
	TOKEN_OPAQUE		=> 0xC3,
	TOKEN_LITERAL_AC	=> 0xC4,
};

# From WAP-192-WBXML-20010725-a table 5 ("Public Identifiers") and
# http://www.openmobilealliance.org/tech/omna/omna-wbxml-public-docid.aspx
my %public_id = (
	0 => 'String table index',
	1 => 'Unknown',
	2 => "-//WAPFORUM//DTD WML 1.0//EN",
	3 => "-//WAPFORUM//DTD WTA 1.0//EN",
	4 => "-//WAPFORUM//DTD WML 1.1//EN",
	5 => "-//WAPFORUM//DTD SI 1.0//EN",
	6 => "-//WAPFORUM//DTD SL 1.0//EN",
	7 => "-//WAPFORUM//DTD CO 1.0//EN",
	8 => "-//WAPFORUM//DTD CHANNEL 1.1//EN",
	9 => "-//WAPFORUM//DTD WML 1.2//EN",
	10 => "-//WAPFORUM//DTD WML 1.3//EN",
	11 => "-//WAPFORUM//DTD PROV 1.0//EN",
	12 => "-//WAPFORUM//DTD WTA-WML 1.2//EN",
	13 => "-//WAPFORUM//DTD EMN 1.0//EN",
	14 => "-//OMA//DTD DRMREL 1.0//EN",
	15 => "-//WIRELESSVILLAGE//DTD CSP 1.0//EN",
	16 => "-//WIRELESSVILLAGE//DTD CSP 1.1//EN",
	17 => "-//OMA//DTD WV-CSP 1.2//EN",
	18 => "-//OMA//DTD IMPS-CSP 1.3//EN",
	19 => "-//OMA//DRM 2.1//EN",
	20 => "-//OMA//SRM 1.0//EN",
	21 => "-//OMA//DCD 1.0//EN",
	22 => "-//OMA//DTD DS-DataObjectEmail 1.2//EN",



( run in 0.950 second using v1.01-cache-2.11-cpan-140bd7fdf52 )