Parse::Binary::Iterative - Parse binary structures
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', ]);
open IN, "something.ico"; my $iconfile = IconFile->new(\*IN); my $icons = $iconfile->Count; my $width = $iconfile->Icon->Width;
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.
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
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.)
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.
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.