Simon Cozens > Parse-Binary-Iterative-1.00 > Parse::Binary::Iterative

Download:
Parse-Binary-Iterative-1.00.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.00   Source  

NAME ^

Parse::Binary::Iterative - Parse binary structures

SYNOPSIS ^

A simple structure:

    package Simple;
    use base 'Parse::Binary::Iterative';
    __PACKAGE__->FORMAT([
        One => "A",
        Two => "V",
        Three => "d",
    ]);

A structure relying on another structure:

    package IconFile;
    use base 'Parse::Binary::Iterative';
    __PACKAGE__->FORMAT([
    Magic       => 'a2',
    Type        => 'v',
    Count       => 'v',
    Icon        => [], # This links to another structure
    Data        => 'a*',
    ]);

    package Icon;
    use base 'Parse::Binary::Iterative';
    __PACKAGE__->FORMAT([
    Width       => 'C',
    Height      => 'C',
    ColorCount  => 'C',
    Reserved    => 'C',
    Planes      => 'v',
    BitCount    => 'v',
    ImageSize   => 'V',
    ImageOffset => 'v',
    ]);

Reading data:

    open IN, "something.ico";
    my $iconfile = IconFile->new(\*IN);
    my $icons = $iconfile->Count;
    my $width = $iconfile->Icon->Width;

DESCRIPTION ^

This module is more or less a reproduction of Parse::Binary with slightly less functionality, more documentation and some tests, and with the ability to read data sequentially from a filehandle instead of having to slurp it all in at once.

USAGE

You use this module by subclassing it and creating classes which represent the structures you're trying to unpack. As shown in the examples above, you need to set the FORMAT class data accessor to an array reference; this should contain pairs of accessor names and formats suitable for feeding to unpack.

If you want to do more complex stuff with your data format, use an array reference instead of a Perl format. This allows you to do the following: (This list will grow in future versons.)

SEE ALSO ^

Parse::Binary

AUTHOR ^

Simon Cozens

COPYRIGHT AND LICENSE ^

Copyright (C) 2006 by Simon Cozens

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: