.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Parse::Binary::FixedFormat::Variants 3pm" .TH Parse::Binary::FixedFormat::Variants 3pm "2018-12-20" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Parse::Binary::FixedFormat::Variants \- Convert between variant records and hashes .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBParse::Binary::FixedFormat\fR supports variant record formats. To describe a variant structure, pass a hash reference containing the following elements to \fBnew\fR. The object returned to handle variant records will be a \fBParse::Binary::FixedFormat::Variants\fR. .IP "Chooser" 4 .IX Item "Chooser" When converting a buffer to a hash, this subroutine is invoked after applying the first format to the buffer. The generated hash reference is passed to this routine. Any field names specified in the first format are available to be used in making a decision on which format to use to decipher the buffer. This routine should return the index of the proper format specification. .Sp When converting a hash to a buffer, this subroutine is invoked first to choose a packing format. Since the same function is used for both conversions, this function should restrict itself to field names that exist in format 0 and those fields should exist in the same place in all formats. .IP "Formats" 4 .IX Item "Formats" This is a reference to a list of formats. Each format contains a list of field specifications. .PP For example: .PP .Vb 10 \& my $cvt = new Parse::Binary::FixedFormat { \& Chooser => sub { my $rec=shift; \& $rec\->{RecordType} eq \*(Aq0\*(Aq ? 1 : 2 \& }, \& Formats => [ [ \*(AqRecordType:A1\*(Aq ], \& [ \*(AqRecordType:A1\*(Aq, \*(AqFieldA:A6\*(Aq, \*(AqFieldB:A4:4\*(Aq ], \& [ \*(AqRecordType:A1\*(Aq, \*(AqFieldC:A4\*(Aq, \*(AqFieldD:A18\*(Aq ] ] \& }; \& my $rec0 = $cvt\->unformat("0FieldAB[0]B[1]B[2]B[3]"); \& my $rec1 = $cvt\->unformat("1FldC<\-\-\-\-\-FieldD\-\-\-\-\->"); .Ve .PP In the above example, the \f(CW\*(C`Chooser\*(C'\fR function looks at the contents of the \f(CW\*(C`RecordType\*(C'\fR field. If it contains a '0', format 1 is used. Otherwise, format 2 is used. .PP \&\fBParse::Binary::FixedFormat::Variants\fR can be used is if it were a \&\fBParse::Binary::FixedFormat\fR. The \f(CW\*(C`format\*(C'\fR and \f(CW\*(C`unformat\*(C'\fR methods will determine which variant to use automatically. The \f(CW\*(C`blank\*(C'\fR method requires an argument that specifies the variant number. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Each Parse::Binary::FixedFormat::Variants instance contains the following attributes. .IP "Layouts" 4 .IX Item "Layouts" Contains an array of Parse::Binary::FixedFormat objects. Each of these objects is responsible for converting a single record format variant. .IP "Chooser" 4 .IX Item "Chooser" This attribute contains the function that chooses which variant to apply to the record. .SH "AUTHORS" .IX Header "AUTHORS" Audrey Tang .PP Based on Data::FixedFormat::Variants, written by Thomas Pfau http://nbpfaus.net/~pfau/. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2004\-2009 by Audrey Tang . .PP Copyright (C) 2000,2002 Thomas Pfau. All rights reserved. .PP This module is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. .PP This library is distributed in the hope that it will be useful, but \&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \s-1GNU\s0 Library General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place \- Suite 330, Boston, \s-1MA 02111\-1307, USA.\s0