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.)

  • If the array is two elements and the second is a code reference, the the first will be taken as an unpack format, and then the reader will "transform" the result of the unpack by passing it to the code reference.

  • If you want to "contract out" unpacking to a sub-structure, (see Parse::Binary) use an empty array reference instead of a format, and the name of the accessor will be taken as a class name to use instead.

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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 186:

You forgot a '=back' before '=head1'