Parse-Binary-0.11/0000755000076500007650000000000011136665653013671 5ustar audreytaudreytParse-Binary-0.11/Artistic0000644000076500007650000001373710146702614015376 0ustar audreytaudreyt The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Parse-Binary-0.11/Changes0000644000076500007650000000351011136665024015153 0ustar audreytaudreyt[Changes for 0.11 - 2009-01-25] * When formatting a structure, repeating a variable-counted field 0 times should result in no output, instead of a literal ARRAY(...) string. Contributed by: Werner Höhrer [Changes for 0.10 - 2006-07-07] * Updated Module::Install to 0.63. * Updated Audrey's contact information. [Changes for 0.09 - 2004-12-24] * In Parse::Binary::FixedFormat's lazy_unformat, remove dangling cyclic references to reduce memory leakage. [Changes for 0.08 - 2004-09-08] * In Parse::Binary::FixedFormat, pass data around by reference instead of by value to reduce memory usage. [Changes for 0.07 - 2004-03-16] * Fix incompatibility with 5.6.x due to mixing "use integer" and "$] < 5.008". * Bump version for FixedFormat too. * Even more optimisations. * Cache sibling_index for more speed gain * Cache is_type. * Properly implement nested lazy loading. [Changes for 0.06 - 2004-02-17] * Allow "__" to be used as "::" in is_type(). * True lazy iterating of trailing members. * Deprecate flyweight cache in favor of generators. * Lazy loading of members via next_member implemented. * Recommend Scalar::Util now. * New function set_output_file(), next_member(), callback() and callback_members() [Changes for 0.05 - 2004-02-15] * Fields with name as '_' now means "choose an unique name for me". there can be multiple such fields, and they won't overlap. * New control constant ENCODED_FIELDS (default to 'Data'), that controls which fields get affected by ENCODING. [Changes for 0.04 - 2004-02-15] * Remove an unneccessary ->refresh after set_members. [Changes for 0.03 - 2004-02-14] * Properly handles "(format)*" style formats in 5.6.x. [Changes for 0.02 - 2004-02-13] * More fixes for Perl 5.6. * Make $count safe to use for Perl 5.6. * Fix small POD typos. [Changes for 0.01 - 2004-02-13] * Initial CPAN release. Parse-Binary-0.11/COPYING0000644000076500007650000004307010146702614014715 0ustar audreytaudreyt GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. Parse-Binary-0.11/inc/0000755000076500007650000000000011136665651014440 5ustar audreytaudreytParse-Binary-0.11/inc/Module/0000755000076500007650000000000011136665651015665 5ustar audreytaudreytParse-Binary-0.11/inc/Module/Install/0000755000076500007650000000000011136665651017273 5ustar audreytaudreytParse-Binary-0.11/inc/Module/Install/Base.pm0000644000076500007650000000205011136665573020503 0ustar audreytaudreyt#line 1 package Module::Install::Base; $VERSION = '0.77'; # Suspend handler for "redefined" warnings BEGIN { my $w = $SIG{__WARN__}; $SIG{__WARN__} = sub { $w }; } ### This is the ONLY module that shouldn't have strict on # use strict; #line 41 sub new { my ($class, %args) = @_; foreach my $method ( qw(call load) ) { *{"$class\::$method"} = sub { shift()->_top->$method(@_); } unless defined &{"$class\::$method"}; } bless( \%args, $class ); } #line 61 sub AUTOLOAD { my $self = shift; local $@; my $autoload = eval { $self->_top->autoload } or return; goto &$autoload; } #line 76 sub _top { $_[0]->{_top} } #line 89 sub admin { $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new; } #line 101 sub is_admin { $_[0]->admin->VERSION; } sub DESTROY {} package Module::Install::Base::FakeAdmin; my $Fake; sub new { $Fake ||= bless(\@_, $_[0]) } sub AUTOLOAD {} sub DESTROY {} # Restore warning handler BEGIN { $SIG{__WARN__} = $SIG{__WARN__}->(); } 1; #line 146 Parse-Binary-0.11/inc/Module/Install/Can.pm0000644000076500007650000000342211136665573020336 0ustar audreytaudreyt#line 1 package Module::Install::Can; use strict; use Module::Install::Base; use Config (); ### This adds a 5.005 Perl version dependency. ### This is a bug and will be fixed. use File::Spec (); use ExtUtils::MakeMaker (); use vars qw{$VERSION $ISCORE @ISA}; BEGIN { $VERSION = '0.77'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } # check if we can load some module ### Upgrade this to not have to load the module if possible sub can_use { my ($self, $mod, $ver) = @_; $mod =~ s{::|\\}{/}g; $mod .= '.pm' unless $mod =~ /\.pm$/i; my $pkg = $mod; $pkg =~ s{/}{::}g; $pkg =~ s{\.pm$}{}i; local $@; eval { require $mod; $pkg->VERSION($ver || 0); 1 }; } # check if we can run some command sub can_run { my ($self, $cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; my $abs = File::Spec->catfile($dir, $_[1]); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # can we locate a (the) C compiler sub can_cc { my $self = shift; my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return $self->can_run("@chunks") || (pop(@chunks), next); } return; } # Fix Cygwin bug on maybe_command(); if ( $^O eq 'cygwin' ) { require ExtUtils::MM_Cygwin; require ExtUtils::MM_Win32; if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { *ExtUtils::MM_Cygwin::maybe_command = sub { my ($self, $file) = @_; if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { ExtUtils::MM_Win32->maybe_command($file); } else { ExtUtils::MM_Unix->maybe_command($file); } } } } 1; __END__ #line 158 Parse-Binary-0.11/inc/Module/Install/Fetch.pm0000644000076500007650000000463011136665573020670 0ustar audreytaudreyt#line 1 package Module::Install::Fetch; use strict; use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { $VERSION = '0.77'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } sub get_file { my ($self, %args) = @_; my ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) { $args{url} = $args{ftp_url} or (warn("LWP support unavailable!\n"), return); ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; } $|++; print "Fetching '$file' from $host... "; unless (eval { require Socket; Socket::inet_aton($host) }) { warn "'$host' resolve failed!\n"; return; } return unless $scheme eq 'ftp' or $scheme eq 'http'; require Cwd; my $dir = Cwd::getcwd(); chdir $args{local_dir} or return if exists $args{local_dir}; if (eval { require LWP::Simple; 1 }) { LWP::Simple::mirror($args{url}, $file); } elsif (eval { require Net::FTP; 1 }) { eval { # use Net::FTP to get past firewall my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600); $ftp->login("anonymous", 'anonymous@example.com'); $ftp->cwd($path); $ftp->binary; $ftp->get($file) or (warn("$!\n"), return); $ftp->quit; } } elsif (my $ftp = $self->can_run('ftp')) { eval { # no Net::FTP, fallback to ftp.exe require FileHandle; my $fh = FileHandle->new; local $SIG{CHLD} = 'IGNORE'; unless ($fh->open("|$ftp -n")) { warn "Couldn't open ftp: $!\n"; chdir $dir; return; } my @dialog = split(/\n/, <<"END_FTP"); open $host user anonymous anonymous\@example.com cd $path binary get $file $file quit END_FTP foreach (@dialog) { $fh->print("$_\n") } $fh->close; } } else { warn "No working 'ftp' program available!\n"; chdir $dir; return; } unless (-f $file) { warn "Fetching failed: $@\n"; chdir $dir; return; } return if exists $args{size} and -s $file != $args{size}; system($args{run}) if exists $args{run}; unlink($file) if $args{remove}; print(((!exists $args{check_for} or -e $args{check_for}) ? "done!" : "failed! ($!)"), "\n"); chdir $dir; return !$?; } 1; Parse-Binary-0.11/inc/Module/Install/Makefile.pm0000644000076500007650000001454611136665573021363 0ustar audreytaudreyt#line 1 package Module::Install::Makefile; use strict 'vars'; use Module::Install::Base; use ExtUtils::MakeMaker (); use vars qw{$VERSION $ISCORE @ISA}; BEGIN { $VERSION = '0.77'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } sub Makefile { $_[0] } my %seen = (); sub prompt { shift; # Infinite loop protection my @c = caller(); if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; } # In automated testing, always use defaults if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) { local $ENV{PERL_MM_USE_DEFAULT} = 1; goto &ExtUtils::MakeMaker::prompt; } else { goto &ExtUtils::MakeMaker::prompt; } } sub makemaker_args { my $self = shift; my $args = ( $self->{makemaker_args} ||= {} ); %$args = ( %$args, @_ ); return $args; } # For mm args that take multiple space-seperated args, # append an argument to the current list. sub makemaker_append { my $self = sShift; my $name = shift; my $args = $self->makemaker_args; $args->{name} = defined $args->{$name} ? join( ' ', $args->{name}, @_ ) : join( ' ', @_ ); } sub build_subdirs { my $self = shift; my $subdirs = $self->makemaker_args->{DIR} ||= []; for my $subdir (@_) { push @$subdirs, $subdir; } } sub clean_files { my $self = shift; my $clean = $self->makemaker_args->{clean} ||= {}; %$clean = ( %$clean, FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_), ); } sub realclean_files { my $self = shift; my $realclean = $self->makemaker_args->{realclean} ||= {}; %$realclean = ( %$realclean, FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_), ); } sub libs { my $self = shift; my $libs = ref $_[0] ? shift : [ shift ]; $self->makemaker_args( LIBS => $libs ); } sub inc { my $self = shift; $self->makemaker_args( INC => shift ); } my %test_dir = (); sub _wanted_t { /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1; } sub tests_recursive { my $self = shift; if ( $self->tests ) { die "tests_recursive will not work if tests are already defined"; } my $dir = shift || 't'; unless ( -d $dir ) { die "tests_recursive dir '$dir' does not exist"; } %test_dir = (); require File::Find; File::Find::find( \&_wanted_t, $dir ); $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir ); } sub write { my $self = shift; die "&Makefile->write() takes no arguments\n" if @_; # Make sure we have a new enough require ExtUtils::MakeMaker; # MakeMaker can complain about module versions that include # an underscore, even though its own version may contain one! # Hence the funny regexp to get rid of it. See RT #35800 # for details. $self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ ); # Generate the my $args = $self->makemaker_args; $args->{DISTNAME} = $self->name; $args->{NAME} = $self->module_name || $self->name; $args->{VERSION} = $self->version; $args->{NAME} =~ s/-/::/g; if ( $self->tests ) { $args->{test} = { TESTS => $self->tests }; } if ($] >= 5.005) { $args->{ABSTRACT} = $self->abstract; $args->{AUTHOR} = $self->author; } if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) { $args->{NO_META} = 1; } if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) { $args->{SIGN} = 1; } unless ( $self->is_admin ) { delete $args->{SIGN}; } # merge both kinds of requires into prereq_pm my $prereq = ($args->{PREREQ_PM} ||= {}); %$prereq = ( %$prereq, map { @$_ } map { @$_ } grep $_, ($self->configure_requires, $self->build_requires, $self->requires) ); # Remove any reference to perl, PREREQ_PM doesn't support it delete $args->{PREREQ_PM}->{perl}; # merge both kinds of requires into prereq_pm my $subdirs = ($args->{DIR} ||= []); if ($self->bundles) { foreach my $bundle (@{ $self->bundles }) { my ($file, $dir) = @$bundle; push @$subdirs, $dir if -d $dir; delete $prereq->{$file}; } } if ( my $perl_version = $self->perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; } $args->{INSTALLDIRS} = $self->installdirs; my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args; my $user_preop = delete $args{dist}->{PREOP}; if (my $preop = $self->admin->preop($user_preop)) { foreach my $key ( keys %$preop ) { $args{dist}->{$key} = $preop->{$key}; } } my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); } sub fix_up_makefile { my $self = shift; my $makefile_name = shift; my $top_class = ref($self->_top) || ''; my $top_version = $self->_top->VERSION || ''; my $preamble = $self->preamble ? "# Preamble by $top_class $top_version\n" . $self->preamble : ''; my $postamble = "# Postamble by $top_class $top_version\n" . ($self->postamble || ''); local *MAKEFILE; open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; my $makefile = do { local $/; }; close MAKEFILE or die $!; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; # Module::Install will never be used to build the Core Perl # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g; # XXX - This is currently unused; not sure if it breaks other MM-users # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; print MAKEFILE "$preamble$makefile$postamble" or die $!; close MAKEFILE or die $!; 1; } sub preamble { my ($self, $text) = @_; $self->{preamble} = $text . $self->{preamble} if defined $text; $self->{preamble}; } sub postamble { my ($self, $text) = @_; $self->{postamble} ||= $self->admin->postamble; $self->{postamble} .= $text if defined $text; $self->{postamble} } 1; __END__ #line 379 Parse-Binary-0.11/inc/Module/Install/Metadata.pm0000644000076500007650000002700211136665573021355 0ustar audreytaudreyt#line 1 package Module::Install::Metadata; use strict 'vars'; use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { $VERSION = '0.77'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } my @scalar_keys = qw{ name module_name abstract author version distribution_type tests installdirs }; my @tuple_keys = qw{ configure_requires build_requires requires recommends bundles resources }; my @resource_keys = qw{ homepage bugtracker repository }; sub Meta { shift } sub Meta_ScalarKeys { @scalar_keys } sub Meta_TupleKeys { @tuple_keys } sub Meta_ResourceKeys { @resource_keys } foreach my $key ( @scalar_keys ) { *$key = sub { my $self = shift; return $self->{values}{$key} if defined wantarray and !@_; $self->{values}{$key} = shift; return $self; }; } foreach my $key ( @resource_keys ) { *$key = sub { my $self = shift; unless ( @_ ) { return () unless $self->{values}{resources}; return map { $_->[1] } grep { $_->[0] eq $key } @{ $self->{values}{resources} }; } return $self->{values}{resources}{$key} unless @_; my $uri = shift or die( "Did not provide a value to $key()" ); $self->resources( $key => $uri ); return 1; }; } sub requires { my $self = shift; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @{ $self->{values}{requires} }, [ $module, $version ]; } $self->{values}{requires}; } sub build_requires { my $self = shift; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @{ $self->{values}{build_requires} }, [ $module, $version ]; } $self->{values}{build_requires}; } sub configure_requires { my $self = shift; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @{ $self->{values}{configure_requires} }, [ $module, $version ]; } $self->{values}{configure_requires}; } sub recommends { my $self = shift; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @{ $self->{values}{recommends} }, [ $module, $version ]; } $self->{values}{recommends}; } sub bundles { my $self = shift; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @{ $self->{values}{bundles} }, [ $module, $version ]; } $self->{values}{bundles}; } # Resource handling my %lc_resource = map { $_ => 1 } qw{ homepage license bugtracker repository }; sub resources { my $self = shift; while ( @_ ) { my $name = shift or last; my $value = shift or next; if ( $name eq lc $name and ! $lc_resource{$name} ) { die("Unsupported reserved lowercase resource '$name'"); } $self->{values}{resources} ||= []; push @{ $self->{values}{resources} }, [ $name, $value ]; } $self->{values}{resources}; } # Aliases for build_requires that will have alternative # meanings in some future version of META.yml. sub test_requires { shift->build_requires(@_) } sub install_requires { shift->build_requires(@_) } # Aliases for installdirs options sub install_as_core { $_[0]->installdirs('perl') } sub install_as_cpan { $_[0]->installdirs('site') } sub install_as_site { $_[0]->installdirs('site') } sub install_as_vendor { $_[0]->installdirs('vendor') } sub sign { my $self = shift; return $self->{values}{sign} if defined wantarray and ! @_; $self->{values}{sign} = ( @_ ? $_[0] : 1 ); return $self; } sub dynamic_config { my $self = shift; unless ( @_ ) { warn "You MUST provide an explicit true/false value to dynamic_config\n"; return $self; } $self->{values}{dynamic_config} = $_[0] ? 1 : 0; return 1; } sub perl_version { my $self = shift; return $self->{values}{perl_version} unless @_; my $version = shift or die( "Did not provide a value to perl_version()" ); # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to # numbers (eg, 5.006001 or 5.008009). $version =~ s/^(\d+)\.(\d+)\.(\d+)$/sprintf("%d.%03d%03d",$1,$2,$3)/e; $version =~ s/_.+$//; $version = $version + 0; # Numify unless ( $version >= 5.005 ) { die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; } $self->{values}{perl_version} = $version; return 1; } sub license { my $self = shift; return $self->{values}{license} unless @_; my $license = shift or die( 'Did not provide a value to license()' ); $self->{values}{license} = $license; # Automatically fill in license URLs if ( $license eq 'perl' ) { $self->resources( license => 'http://dev.perl.org/licenses/' ); } return 1; } sub all_from { my ( $self, $file ) = @_; unless ( defined($file) ) { my $name = $self->name or die( "all_from called with no args without setting name() first" ); $file = join('/', 'lib', split(/-/, $name)) . '.pm'; $file =~ s{.*/}{} unless -e $file; unless ( -e $file ) { die("all_from cannot find $file from $name"); } } unless ( -f $file ) { die("The path '$file' does not exist, or is not a file"); } # Some methods pull from POD instead of code. # If there is a matching .pod, use that instead my $pod = $file; $pod =~ s/\.pm$/.pod/i; $pod = $file unless -e $pod; # Pull the different values $self->name_from($file) unless $self->name; $self->version_from($file) unless $self->version; $self->perl_version_from($file) unless $self->perl_version; $self->author_from($pod) unless $self->author; $self->license_from($pod) unless $self->license; $self->abstract_from($pod) unless $self->abstract; return 1; } sub provides { my $self = shift; my $provides = ( $self->{values}{provides} ||= {} ); %$provides = (%$provides, @_) if @_; return $provides; } sub auto_provides { my $self = shift; return $self unless $self->is_admin; unless (-e 'MANIFEST') { warn "Cannot deduce auto_provides without a MANIFEST, skipping\n"; return $self; } # Avoid spurious warnings as we are not checking manifest here. local $SIG{__WARN__} = sub {1}; require ExtUtils::Manifest; local *ExtUtils::Manifest::manicheck = sub { return }; require Module::Build; my $build = Module::Build->new( dist_name => $self->name, dist_version => $self->version, license => $self->license, ); $self->provides( %{ $build->find_dist_packages || {} } ); } sub feature { my $self = shift; my $name = shift; my $features = ( $self->{values}{features} ||= [] ); my $mods; if ( @_ == 1 and ref( $_[0] ) ) { # The user used ->feature like ->features by passing in the second # argument as a reference. Accomodate for that. $mods = $_[0]; } else { $mods = \@_; } my $count = 0; push @$features, ( $name => [ map { ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_ } @$mods ] ); return @$features; } sub features { my $self = shift; while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) { $self->feature( $name, @$mods ); } return $self->{values}{features} ? @{ $self->{values}{features} } : (); } sub no_index { my $self = shift; my $type = shift; push @{ $self->{values}{no_index}{$type} }, @_ if $type; return $self->{values}{no_index}; } sub read { my $self = shift; $self->include_deps( 'YAML::Tiny', 0 ); require YAML::Tiny; my $data = YAML::Tiny::LoadFile('META.yml'); # Call methods explicitly in case user has already set some values. while ( my ( $key, $value ) = each %$data ) { next unless $self->can($key); if ( ref $value eq 'HASH' ) { while ( my ( $module, $version ) = each %$value ) { $self->can($key)->($self, $module => $version ); } } else { $self->can($key)->($self, $value); } } return $self; } sub write { my $self = shift; return $self unless $self->is_admin; $self->admin->write_meta; return $self; } sub version_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->version( ExtUtils::MM_Unix->parse_version($file) ); } sub abstract_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->abstract( bless( { DISTNAME => $self->name }, 'ExtUtils::MM_Unix' )->parse_abstract($file) ); } # Add both distribution and module name sub name_from { my ($self, $file) = @_; if ( Module::Install::_read($file) =~ m/ ^ \s* package \s* ([\w:]+) \s* ; /ixms ) { my ($name, $module_name) = ($1, $1); $name =~ s{::}{-}g; $self->name($name); unless ( $self->module_name ) { $self->module_name($module_name); } } else { die("Cannot determine name from $file\n"); } } sub perl_version_from { my $self = shift; if ( Module::Install::_read($_[0]) =~ m/ ^ (?:use|require) \s* v? ([\d_\.]+) \s* ; /ixms ) { my $perl_version = $1; $perl_version =~ s{_}{}g; $self->perl_version($perl_version); } else { warn "Cannot determine perl version info from $_[0]\n"; return; } } sub author_from { my $self = shift; my $content = Module::Install::_read($_[0]); if ($content =~ m/ =head \d \s+ (?:authors?)\b \s* ([^\n]*) | =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]*) /ixms) { my $author = $1 || $2; $author =~ s{E}{<}g; $author =~ s{E}{>}g; $self->author($author); } else { warn "Cannot determine author info from $_[0]\n"; } } sub license_from { my $self = shift; if ( Module::Install::_read($_[0]) =~ m/ ( =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b .*? ) (=head\\d.*|=cut.*|) \z /ixms ) { my $license_text = $1; my @phrases = ( 'under the same (?:terms|license) as perl itself' => 'perl', 1, 'GNU general public license' => 'gpl', 1, 'GNU public license' => 'gpl', 1, 'GNU lesser general public license' => 'lgpl', 1, 'GNU lesser public license' => 'lgpl', 1, 'GNU library general public license' => 'lgpl', 1, 'GNU library public license' => 'lgpl', 1, 'BSD license' => 'bsd', 1, 'Artistic license' => 'artistic', 1, 'GPL' => 'gpl', 1, 'LGPL' => 'lgpl', 1, 'BSD' => 'bsd', 1, 'Artistic' => 'artistic', 1, 'MIT' => 'mit', 1, 'proprietary' => 'proprietary', 0, ); while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { $pattern =~ s{\s+}{\\s+}g; if ( $license_text =~ /\b$pattern\b/i ) { if ( $osi and $license_text =~ /All rights reserved/i ) { print "WARNING: 'All rights reserved' in copyright may invalidate Open Source license.\n"; } $self->license($license); return 1; } } } warn "Cannot determine license info from $_[0]\n"; return 'unknown'; } sub bugtracker_from { my $self = shift; my $content = Module::Install::_read($_[0]); my @links = $content =~ m/L\<(http\:\/\/rt\.cpan\.org\/[^>]+)\>/g; unless ( @links ) { warn "Cannot determine bugtracker info from $_[0]\n"; return 0; } if ( @links > 1 ) { warn "Found more than on rt.cpan.org link in $_[0]\n"; return 0; } # Set the bugtracker bugtracker( $links[0] ); return 1; } sub install_script { my $self = shift; my $args = $self->makemaker_args; my $exe = $args->{EXE_FILES} ||= []; foreach ( @_ ) { if ( -f $_ ) { push @$exe, $_; } elsif ( -d 'script' and -f "script/$_" ) { push @$exe, "script/$_"; } else { die("Cannot find script '$_'"); } } } 1; Parse-Binary-0.11/inc/Module/Install/Win32.pm0000644000076500007650000000340211136665573020535 0ustar audreytaudreyt#line 1 package Module::Install::Win32; use strict; use Module::Install::Base; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '0.77'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } # determine if the user needs nmake, and download it if needed sub check_nmake { my $self = shift; $self->load('can_run'); $self->load('get_file'); require Config; return unless ( $^O eq 'MSWin32' and $Config::Config{make} and $Config::Config{make} =~ /^nmake\b/i and ! $self->can_run('nmake') ); print "The required 'nmake' executable not found, fetching it...\n"; require File::Basename; my $rv = $self->get_file( url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe', ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe', local_dir => File::Basename::dirname($^X), size => 51928, run => 'Nmake15.exe /o > nul', check_for => 'Nmake.exe', remove => 1, ); die <<'END_MESSAGE' unless $rv; ------------------------------------------------------------------------------- Since you are using Microsoft Windows, you will need the 'nmake' utility before installation. It's available at: http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe or ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe Please download the file manually, save it to a directory in %PATH% (e.g. C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to that directory, and run "Nmake15.exe" from there; that will create the 'nmake.exe' file needed by this module. You may then resume the installation process described in README. ------------------------------------------------------------------------------- END_MESSAGE } 1; Parse-Binary-0.11/inc/Module/Install/WriteAll.pm0000644000076500007650000000132111136665573021354 0ustar audreytaudreyt#line 1 package Module::Install::WriteAll; use strict; use Module::Install::Base; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '0.77'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } sub WriteAll { my $self = shift; my %args = ( meta => 1, sign => 0, inline => 0, check_nmake => 1, @_, ); $self->sign(1) if $args{sign}; $self->Meta->write if $args{meta}; $self->admin->WriteAll(%args) if $self->is_admin; $self->check_nmake if $args{check_nmake}; unless ( $self->makemaker_args->{PL_FILES} ) { $self->makemaker_args( PL_FILES => {} ); } if ( $args{inline} ) { $self->Inline->write; } else { $self->Makefile->write; } } 1; Parse-Binary-0.11/inc/Module/Install.pm0000644000076500007650000002116211136665573017636 0ustar audreytaudreyt#line 1 package Module::Install; # For any maintainers: # The load order for Module::Install is a bit magic. # It goes something like this... # # IF ( host has Module::Install installed, creating author mode ) { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install # 3. The installed version of inc::Module::Install loads # 4. inc::Module::Install calls "require Module::Install" # 5. The ./inc/ version of Module::Install loads # } ELSE { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install # 3. The ./inc/ version of Module::Install loads # } BEGIN { require 5.004; } use strict 'vars'; use vars qw{$VERSION}; BEGIN { # All Module::Install core packages now require synchronised versions. # This will be used to ensure we don't accidentally load old or # different versions of modules. # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. $VERSION = '0.77'; *inc::Module::Install::VERSION = *VERSION; @inc::Module::Install::ISA = __PACKAGE__; } # Whether or not inc::Module::Install is actually loaded, the # $INC{inc/Module/Install.pm} is what will still get set as long as # the caller loaded module this in the documented manner. # If not set, the caller may NOT have loaded the bundled version, and thus # they may not have a MI version that works with the Makefile.PL. This would # result in false errors or unexpected behaviour. And we don't want that. my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm'; unless ( $INC{$file} ) { die <<"END_DIE" } Please invoke ${\__PACKAGE__} with: use inc::${\__PACKAGE__}; not: use ${\__PACKAGE__}; END_DIE # If the script that is loading Module::Install is from the future, # then make will detect this and cause it to re-run over and over # again. This is bad. Rather than taking action to touch it (which # is unreliable on some platforms and requires write permissions) # for now we should catch this and refuse to run. if ( -f $0 and (stat($0))[9] > time ) { die <<"END_DIE" } Your installer $0 has a modification time in the future. This is known to create infinite loops in make. Please correct this, then run $0 again. END_DIE # Build.PL was formerly supported, but no longer is due to excessive # difficulty in implementing every single feature twice. if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" } Module::Install no longer supports Build.PL. It was impossible to maintain duel backends, and has been deprecated. Please remove all Build.PL files and only use the Makefile.PL installer. END_DIE # To save some more typing in Module::Install installers, every... # use inc::Module::Install # ...also acts as an implicit use strict. $^H |= strict::bits(qw(refs subs vars)); use Cwd (); use File::Find (); use File::Path (); use FindBin; sub autoload { my $self = shift; my $who = $self->_caller; my $cwd = Cwd::cwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { my $pwd = Cwd::cwd(); if ( my $code = $sym->{$pwd} ) { # delegate back to parent dirs goto &$code unless $cwd eq $pwd; } $$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym"; unless ( uc($1) eq $1 ) { unshift @_, ( $self, $1 ); goto &{$self->can('call')}; } }; } sub import { my $class = shift; my $self = $class->new(@_); my $who = $self->_caller; unless ( -f $self->{file} ) { require "$self->{path}/$self->{dispatch}.pm"; File::Path::mkpath("$self->{prefix}/$self->{author}"); $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self ); $self->{admin}->init; @_ = ($class, _self => $self); goto &{"$self->{name}::import"}; } *{"${who}::AUTOLOAD"} = $self->autoload; $self->preload; # Unregister loader and worker packages so subdirs can use them again delete $INC{"$self->{file}"}; delete $INC{"$self->{path}.pm"}; return 1; } sub preload { my $self = shift; unless ( $self->{extensions} ) { $self->load_extensions( "$self->{prefix}/$self->{path}", $self ); } my @exts = @{$self->{extensions}}; unless ( @exts ) { my $admin = $self->{admin}; @exts = $admin->load_all_extensions; } my %seen; foreach my $obj ( @exts ) { while (my ($method, $glob) = each %{ref($obj) . '::'}) { next unless $obj->can($method); next if $method =~ /^_/; next if $method eq uc($method); $seen{$method}++; } } my $who = $self->_caller; foreach my $name ( sort keys %seen ) { *{"${who}::$name"} = sub { ${"${who}::AUTOLOAD"} = "${who}::$name"; goto &{"${who}::AUTOLOAD"}; }; } } sub new { my ($class, %args) = @_; # ignore the prefix on extension modules built from top level. my $base_path = Cwd::abs_path($FindBin::Bin); unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) { delete $args{prefix}; } return $args{_self} if $args{_self}; $args{dispatch} ||= 'Admin'; $args{prefix} ||= 'inc'; $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author'); $args{bundle} ||= 'inc/BUNDLES'; $args{base} ||= $base_path; $class =~ s/^\Q$args{prefix}\E:://; $args{name} ||= $class; $args{version} ||= $class->VERSION; unless ( $args{path} ) { $args{path} = $args{name}; $args{path} =~ s!::!/!g; } $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm"; $args{wrote} = 0; bless( \%args, $class ); } sub call { my ($self, $method) = @_; my $obj = $self->load($method) or return; splice(@_, 0, 2, $obj); goto &{$obj->can($method)}; } sub load { my ($self, $method) = @_; $self->load_extensions( "$self->{prefix}/$self->{path}", $self ) unless $self->{extensions}; foreach my $obj (@{$self->{extensions}}) { return $obj if $obj->can($method); } my $admin = $self->{admin} or die <<"END_DIE"; The '$method' method does not exist in the '$self->{prefix}' path! Please remove the '$self->{prefix}' directory and run $0 again to load it. END_DIE my $obj = $admin->load($method, 1); push @{$self->{extensions}}, $obj; $obj; } sub load_extensions { my ($self, $path, $top) = @_; unless ( grep { lc $_ eq lc $self->{prefix} } @INC ) { unshift @INC, $self->{prefix}; } foreach my $rv ( $self->find_extensions($path) ) { my ($file, $pkg) = @{$rv}; next if $self->{pathnames}{$pkg}; local $@; my $new = eval { require $file; $pkg->can('new') }; unless ( $new ) { warn $@ if $@; next; } $self->{pathnames}{$pkg} = delete $INC{$file}; push @{$self->{extensions}}, &{$new}($pkg, _top => $top ); } $self->{extensions} ||= []; } sub find_extensions { my ($self, $path) = @_; my @found; File::Find::find( sub { my $file = $File::Find::name; return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is; my $subpath = $1; return if lc($subpath) eq lc($self->{dispatch}); $file = "$self->{path}/$subpath.pm"; my $pkg = "$self->{name}::$subpath"; $pkg =~ s!/!::!g; # If we have a mixed-case package name, assume case has been preserved # correctly. Otherwise, root through the file to locate the case-preserved # version of the package name. if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { my $content = Module::Install::_read($subpath . '.pm'); my $in_pod = 0; foreach ( split //, $content ) { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); # skip pod text next if /^\s*#/; # and comments if ( m/^\s*package\s+($pkg)\s*;/i ) { $pkg = $1; last; } } } push @found, [ $file, $pkg ]; }, $path ) if -d $path; @found; } ##################################################################### # Utility Functions sub _caller { my $depth = 0; my $call = caller($depth); while ( $call eq __PACKAGE__ ) { $depth++; $call = caller($depth); } return $call; } sub _read { local *FH; open FH, "< $_[0]" or die "open($_[0]): $!"; my $str = do { local $/; }; close FH or die "close($_[0]): $!"; return $str; } sub _write { local *FH; open FH, "> $_[0]" or die "open($_[0]): $!"; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!" } close FH or die "close($_[0]): $!"; } # _version is for processing module versions (eg, 1.03_05) not # Perl versions (eg, 5.8.1). sub _version ($) { my $s = shift || 0; $s =~ s/^(\d+)\.?//; my $l = $1 || 0; my @v = map { $_ . '0' x (3 - length $_) } $s =~ /(\d{1,3})\D?/g; $l = $l . '.' . join '', @v if @v; return $l + 0; } # Cloned from Params::Util::_CLASS sub _CLASS ($) { ( defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*$/s ) ? $_[0] : undef; } 1; # Copyright 2008 Adam Kennedy. Parse-Binary-0.11/lib/0000755000076500007650000000000011136665651014435 5ustar audreytaudreytParse-Binary-0.11/lib/Parse/0000755000076500007650000000000011136665651015507 5ustar audreytaudreytParse-Binary-0.11/lib/Parse/Binary/0000755000076500007650000000000011136665651016733 5ustar audreytaudreytParse-Binary-0.11/lib/Parse/Binary/FixedFormat/0000755000076500007650000000000011136665651021143 5ustar audreytaudreytParse-Binary-0.11/lib/Parse/Binary/FixedFormat/Variants.pm0000644000076500007650000001050711136665642023273 0ustar audreytaudreytpackage Parse::Binary::FixedFormat::Variants; use strict; our $VERSION = "0.03"; sub new { my ($class,$recfmt) = @_; my $self; $self = { Layouts=>[], Chooser=>$recfmt->{Chooser}, Formats => $recfmt->{Formats} }; bless $self, $class; foreach my $fmt (@{$recfmt->{Formats}}) { push @{$self->{Layouts}},new Parse::Binary::FixedFormat $fmt; } return $self; } sub unformat { my ($self,$frec) = @_; my $rec = $self->{Layouts}[0]->unformat($frec); if ($self->{Chooser}) { my $w = &{$self->{Chooser}}($rec, $self, 'unformat'); $rec = $self->{Layouts}[$w]->unformat($frec) if $w; } return $rec; } sub format { my ($self,$rec) = @_; my $w = 0; if ($self->{Chooser}) { $w = &{$self->{Chooser}}($rec, $self, 'format'); } my $frec = $self->{Layouts}[$w]->format($rec); return $frec; } sub blank { my ($self,$w) = @_; $w = 0 unless $w; my $rec = $self->{Layouts}[$w]->blank(); return $rec; } 1; =head1 NAME Parse::Binary::FixedFormat::Variants - Convert between variant records and hashes =head1 DESCRIPTION B supports variant record formats. To describe a variant structure, pass a hash reference containing the following elements to B. The object returned to handle variant records will be a B. =over 4 =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. 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. =item Formats This is a reference to a list of formats. Each format contains a list of field specifications. =back For example: my $cvt = new Parse::Binary::FixedFormat { Chooser => sub { my $rec=shift; $rec->{RecordType} eq '0' ? 1 : 2 }, Formats => [ [ 'RecordType:A1' ], [ 'RecordType:A1', 'FieldA:A6', 'FieldB:A4:4' ], [ 'RecordType:A1', 'FieldC:A4', 'FieldD:A18' ] ] }; my $rec0 = $cvt->unformat("0FieldAB[0]B[1]B[2]B[3]"); my $rec1 = $cvt->unformat("1FldC<-----FieldD----->"); In the above example, the C function looks at the contents of the C field. If it contains a '0', format 1 is used. Otherwise, format 2 is used. B can be used is if it were a B. The C and C methods will determine which variant to use automatically. The C method requires an argument that specifies the variant number. =head1 ATTRIBUTES Each Parse::Binary::FixedFormat::Variants instance contains the following attributes. =over 4 =item Layouts Contains an array of Parse::Binary::FixedFormat objects. Each of these objects is responsible for converting a single record format variant. =item Chooser This attribute contains the function that chooses which variant to apply to the record. =back =head1 AUTHORS Audrey Tang Ecpan@audreyt.orgE Based on Data::FixedFormat::Variants, written by Thomas Pfau http://nbpfaus.net/~pfau/. =head1 COPYRIGHT Copyright 2004-2009 by Audrey Tang Ecpan@audreyt.orgE. Copyright (C) 2000,2002 Thomas Pfau. All rights reserved. This module is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. =cut Parse-Binary-0.11/lib/Parse/Binary/FixedFormat.pm0000644000076500007650000002017411136664070021477 0ustar audreytaudreytpackage Parse::Binary::FixedFormat; use bytes; use strict; use integer; our $VERSION = '0.05'; sub new { my ($class, $layout) = @_; my $self; if (UNIVERSAL::isa($layout, 'HASH')) { require Parse::Binary::FixedFormat::Variants; $self = Parse::Binary::FixedFormat::Variants->new($layout); } else { $self = { Names=>[], Count=>[], Format=>"" }; bless $self, $class; $self->parse_fields($layout) if $layout; } return $self; } sub parse_fields { my ($self,$fmt) = @_; foreach my $fld (@$fmt) { my ($name, $format, $count, $group) = split /\s*:\s*/,$fld; push @{$self->{Names}}, $name; push @{$self->{Count}}, $count; push @{$self->{Group}}, $group; if (defined $count) { push @{$self->{Format}||=[]}, "($format)$count"; } else { push @{$self->{Format}||=[]}, $format; } } } my %_format_cache; sub _format { my ($self, $lazy) = @_; $self->{_format} ||= do { my $format = join('', @{$self->{Format}}); $_format_cache{$format} ||= do { $format =~ s/\((.*?)\)\*$/a*/ if $lazy; # tail iteration $format =~ s/\((.*?)\)(?:(\d+)|(\*))/$1 x ($3 ? 1 : $2)/eg if ($] < 5.008); $format; }; }; } my %_parent_format; sub unformat { my $self = shift; my @flds = shift; my $lazy = shift; my $parent = shift; my $format = $self->_format($lazy); @flds = unpack($format, $flds[0]) unless $format eq 'a*'; my $rec = {}; foreach my $i (0 .. $#{$self->{Names}}) { my $name = $self->{Names}[$i]; if (defined(my $count = $self->{Count}[$i])) { next unless $count; my $group = $self->{Group}[$i]; if ($count eq '*') { $count = @flds; $group ||= 1; } if ($group) { my $pad = 0; $pad = length($1) if $self->{Format}[$i] =~ /(X+)/; if ($lazy and $i == $#{$self->{Names}}) { my $format = $self->{Format}[$i] or die "No format found"; $format =~ s/^\((.*?)\)\*$/$1/ or die "Not a count=* field"; my $record = ($rec->{$name} ||= []); push @$record, $self->lazy_unformat( $parent, $record, $pad, $format, \($flds[0]) ) if @flds and length($flds[0]); next; } my $count_idx = 0; while (my @content = splice(@flds, 0, $group)) { substr($content[-1], -$pad, $pad, '') if $pad; push @{$rec->{$name}}, \@content; $count_idx += $group; last if $count_idx >= $count; } } else { @{$rec->{$name}} = splice @flds, 0, $count; } } else { $rec->{$name} = shift @flds; } } return $rec; } sub lazy_unformat { my ($self, $parent, $record, $pad, $format, $data) = @_; # for each request of a member data, we: my $valid_sub = ($parent->can('valid_unformat') ? 1 : 0); return sub { { # grab one chunk of data my @content = unpack($format, $$data); my $length = length(pack($format, @content)); # eliminate it from the source string my $chunk = substr($$data, 0, $length, ''); my $done = (length($$data) <= $pad); if ($valid_sub and !$done and !$_[0]->valid_unformat(\@content, \$chunk, $done)) { # weed out invalid data immediately redo; } # remove extra padding substr($content[-1], -$pad, $pad, '') if $pad; # and prepend (or replace if there are no more data) with it splice(@{$_[1]}, -1, $done, \@content); return \@content; } }; } sub format { my ($self,$rec) = @_; my @flds; my $i = 0; foreach my $name (@{$self->{Names}}) { if ($self->{Count}[$i]) { push @flds,map {ref($_) ? @$_ : $_} @{$rec->{$name}}; } else { if (ref($rec->{$name}) eq "ARRAY") { if (@{$rec->{$name}}) { push @flds,$rec->{$name}; } } else { push @flds,$rec->{$name}; } } $i++; } no warnings 'uninitialized'; return pack($self->_format, @flds); } sub blank { my $self = shift; my $rec = $self->unformat(pack($self->_format, unpack($self->_format, ''))); return $rec; } 1; =head1 NAME Parse::Binary::FixedFormat - Convert between fixed-length fields and hashes =head1 SYNOPSIS use Parse::Binary::FixedFormat; my $tarhdr = new Parse::Binary::FixedFormat [ qw(name:a100 mode:a8 uid:a8 gid:a8 size:a12 mtime:a12 chksum:a8 typeflag:a1 linkname:a100 magic:a6 version:a2 uname:a32 gname:a32 devmajor:a8 devminor:a8 prefix:a155) ]; my $buf; read TARFILE, $buf, 512; # create a hash from the buffer read from the file my $hdr = $tarhdr->unformat($buf); # $hdr gets a hash ref # create a flat record from a hash reference my $buf = $tarhdr->format($hdr); # $hdr is a hash ref # create a hash for a new record my $newrec = $tarhdr->blank(); =head1 DESCRIPTION B can be used to convert between a buffer with fixed-length field definitions and a hash with named entries for each field. The perl C and C functions are used to perform the conversions. B builds the format string by concatenating the field descriptions and converts between the lists used by C and C and a hash that can be reference by field name. =head1 METHODS B provides the following methods. =head2 new To create a converter, invoke the B method with a reference to a list of field specifications. my $cvt = new Parse::Binary::FixedFormat [ 'field-name:descriptor:count', ... ]; Field specifications contain the following information. =over 4 =item field-name This is the name of the field and will be used as the hash index. =item descriptor This describes the content and size of the field. All of the descriptors get strung together and passed to B and B as part of the template argument. See B for information on what can be specified here. Don't use repeat counts in the descriptor except for string types ("a", "A", "h, "H", and "Z"). If you want to get an array out of the buffer, use the C argument. =item count This specifies a repeat count for the field. If specified as a non-zero value, this field's entry in the resultant hash will be an array reference instead of a scalar. =back =head2 unformat To convert a buffer of data into a hash, pass the buffer to the B method. $hashref = $cvt->unformat($buf); Parse::Binary::FixedFormat applies the constructed format to the buffer with C and maps the returned list of elements to hash entries. Fields can now be accessed by name though the hash: print $hashref->{field-name}; print $hashref->{array-field}[3]; =head2 format To convert the hash back into a fixed-format buffer, pass the hash reference to the B method. $buf = $cvt->format($hashref); =head2 blank To get a hash that can be used to create a new record, call the B method. $newrec = $cvt->blank(); =head1 ATTRIBUTES Each Parse::Binary::FixedFormat instance contains the following attributes. =over 4 =item Names Names contains a list of the field names for this variant. =item Count Count contains a list of occurrence counts. This is used to indicate which fields contain arrays. =item Format Format contains the template string for the Perl B and B functions. =back =head1 AUTHORS Audrey Tang Ecpan@audreyt.orgE Based on Data::FixedFormat, written by Thomas Pfau http://nbpfaus.net/~pfau/. =head1 COPYRIGHT Copyright 2004-2009 by Audrey Tang Ecpan@audreyt.orgE. Copyright (C) 2000,2002 Thomas Pfau. All rights reserved. This module is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. =cut Parse-Binary-0.11/lib/Parse/Binary.pm0000644000076500007650000005531311136665572017302 0ustar audreytaudreytpackage Parse::Binary; $Parse::Binary::VERSION = '0.11'; use 5.005; use bytes; use strict; use integer; use Parse::Binary::FixedFormat; =head1 NAME Parse::Binary - Unpack binary data structures into object hierarchies =head1 VERSION This document describes version 0.11 of Parse::Binary, released January 25, 2009. =head1 SYNOPSIS # This class represents a Win32 F<.ico> file: package IconFile; use base 'Parse::Binary'; use constant FORMAT => ( Magic => 'a2', Type => 'v', Count => 'v', 'Icon' => [ 'a16', '{$Count}', 1 ], Data => 'a*', ); # An individual icon resource: package Icon; use base 'Parse::Binary'; use constant FORMAT => ( Width => 'C', Height => 'C', ColorCount => 'C', Reserved => 'C', Planes => 'v', BitCount => 'v', ImageSize => 'V', ImageOffset => 'v', ); sub Data { my ($self) = @_; return $self->parent->substr($self->ImageOffset, $self->ImageSize); } # Simple F<.ico> file dumper that uses them: use IconFile; my $icon_file = IconFile->new('input.ico'); foreach my $icon ($icon_file->members) { print "Dimension: ", $icon->Width, "x", $icon->Height, $/; print "Colors: ", 2 ** $icon->BitCount, $/; print "Image Size: ", $icon->ImageSize, " bytes", $/; print "Actual Size: ", length($icon->Data), " bytes", $/, $/; } $icon_file->write('output.ico'); # save as another .ico file =head1 DESCRIPTION This module makes parsing binary data structures much easier, by serving as a base class for classes that represents the binary data, which may contain objects of other classes to represent parts of itself. Documentation is unfortunately a bit lacking at this moment. Please read the tests and source code of L and L for examples of using this module. =cut use constant PROPERTIES => qw( %struct $filename $size $parent @siblings %children $output $lazy $iterator $iterated ); use constant ENCODED_FIELDS => ( 'Data' ); use constant FORMAT => ( Data => 'a*' ); use constant SUBFORMAT => (); use constant DEFAULT_ARGS => (); use constant DELEGATE_SUBS => (); use constant DISPATCH_TABLE => (); use constant DISPATCH_FIELD => undef; use constant BASE_CLASS => undef; use constant ENCODING => undef; use constant PADDING => undef; unless (eval { require Scalar::Util; 1 }) { *Scalar::Util::weaken = sub { 1 }; *Scalar::Util::blessed = sub { UNIVERSAL::can($_[0], 'can') }; } ### Constructors ### sub new { my ($self, $input, $attr) = @_; no strict 'refs'; my $class = $self->class; $class->init unless ${"$class\::init_done"}; $attr ||= {}; $attr->{filename} ||= $input unless ref $input; my $obj = $class->spawn; %$obj = (%$obj, %$attr); my $data = $obj->read_data($input); $obj->load($data, $attr); if ($obj->{lazy}) { $obj->{lazy} = $obj; } elsif (!$obj->{iterator}) { $obj->make_members; } return $obj; } sub dispatch_field { return undef; } use vars qw(%HasMembers %DefaultArgs); use vars qw(%Fields %MemberFields %MemberClass %Packer %Parser %FieldPackFormat); use vars qw(%DispatchField %DispatchTable); sub init { no strict 'refs'; return if ${"$_[0]\::init_done"}; my $class = shift; *{"$class\::class"} = sub { ref($_[0]) || $_[0] }; *{"$class\::is_type"} = \&is_type; foreach my $item ($class->PROPERTIES) { no strict 'refs'; my ($sigil, $name) = split(//, $item, 2); *{"$class\::$name"} = ($sigil eq '$') ? sub { $_[0]{$name} } : ($sigil eq '@') ? sub { wantarray ? @{$_[0]{$name}||=[]} : ($_[0]{$name}||=[]) } : ($sigil eq '%') ? sub { $_[0]{$name}||={} } : die "Unknown sigil: $sigil"; *{"$class\::set_$name"} = ($sigil eq '$') ? sub { $_[0]->{$name} = $_[1] } : ($sigil eq '@') ? sub { @{$_[0]->{$name}||=$_[1]||[]} = @{$_[1]||[]} } : ($sigil eq '%') ? sub { %{$_[0]->{$name}||=$_[1]||{}} = %{$_[1]||{}} } : die "Unknown sigil: $sigil"; } my @args = $class->default_args; *{"$class\::default_args"} = \@args; *{"$class\::default_args"} = sub { @args }; my $delegate_subs = $class->delegate_subs; if (defined(&{"$class\::DELEGATE_SUBS"})) { $delegate_subs = { $class->DELEGATE_SUBS }; } *{"$class\::delegate_subs"} = sub { $delegate_subs }; while (my ($subclass, $methods) = each %$delegate_subs) { $methods = [ $methods ] unless ref $methods; foreach my $method (grep length, @$methods) { *{"$class\::$method"} = sub { goto &{$_[0]->require_class($subclass)->can($method)}; }; } } my $dispatch_table = $class->dispatch_table; if (defined(&{"$class\::DISPATCH_TABLE"})) { $dispatch_table = { $class->DISPATCH_TABLE }; } $DispatchTable{$class} = $dispatch_table; *{"$class\::dispatch_table"} = sub { $dispatch_table }; my $dispatch_field = undef; if (defined(&{"$class\::DISPATCH_FIELD"})) { $dispatch_field = $class->DISPATCH_FIELD; } $DispatchField{$class} = $dispatch_field; *{"$class\::dispatch_field"} = sub { $dispatch_field }; my @format = $class->format_list; if (my @subformat = $class->subformat_list) { my @new_format; while (my ($field, $format) = splice(@format, 0, 2)) { if ($field eq 'Data') { push @new_format, @subformat; } else { push @new_format, ($field => $format); } } @format = @new_format; } my @format_list = @format; *{"$class\::format_list"} = sub { @format_list }; my (@fields, @formats, @pack_formats, $underscore_count); my (%field_format, %field_pack_format); my (%field_parser, %field_packer, %field_length); my (@member_fields, %member_class); while (my ($field, $format) = splice(@format, 0, 2)) { if ($field eq '_') { # "we don't care" fields $underscore_count++; $field = "_${underscore_count}_$class"; $field =~ s/:/_/g; } if (ref $format) { $member_class{$field} = $class->classname($field); $field =~ s/:/_/g; $member_class{$field} = $class->classname($field); $class->require($member_class{$field}); push @member_fields, $field; } else { $format = [ $format ]; } push @fields, $field; my $string = join(':', $field, @$format); $field_format{$field} = [ @$format ]; if (!grep /\{/, @$format) { $field_length{$field} = length(pack($format->[0], 0)); $field_parser{$field} = Parse::Binary::FixedFormat->new( [ $string ] ); } push @formats, $string; s/\s*X\s*//g for @$format; my $pack_string = join(':', $field, @$format); $field_pack_format{$field} = [ @$format ]; $field_packer{$field} = Parse::Binary::FixedFormat->new( [ $pack_string ] ); push @pack_formats, $pack_string; } my $parser = $class->make_formatter(@formats); my $packer = $class->make_formatter(@pack_formats); $Packer{$class} = $packer; $Parser{$class} = $parser; $Fields{$class} = \@fields; $HasMembers{$class} = @member_fields ? 1 : 0; $DefaultArgs{$class} = \@args; $MemberClass{$class} = \%member_class; $MemberFields{$class} = \@member_fields; $FieldPackFormat{$class} = { map { ref($_) ? $_->[0] : $_ } %field_pack_format }; *{"$class\::fields"} = \@fields; *{"$class\::member_fields"} = \@member_fields; *{"$class\::has_members"} = @member_fields ? sub { 1 } : sub { 0 }; *{"$class\::fields"} = sub { @fields }; *{"$class\::formats"} = sub { @formats }; *{"$class\::member_fields"} = sub { @member_fields }; *{"$class\::member_class"} = sub { $member_class{$_[1]} }; *{"$class\::pack_formats"} = sub { @pack_formats }; *{"$class\::field_format"} = sub { $field_format{$_[1]}[0] }; *{"$class\::field_pack_format"} = sub { $field_pack_format{$_[1]}[0] }; *{"$class\::field_length"} = sub { $field_length{$_[1]} }; *{"$class\::parser"} = sub { $parser }; *{"$class\::packer"} = sub { $packer }; *{"$class\::field_parser"} = sub { my ($self, $field) = @_; $field_parser{$field} || do { Parse::Binary::FixedFormat->new( [ $self->eval_format( $self->{struct}, join(':', $field, @{$field_format{$field}}), ), ] ); }; }; *{"$class\::field_packer"} = sub { $field_packer{$_[1]} }; *{"$class\::has_field"} = sub { $field_packer{$_[1]} }; my %enc_fields = map { ($_ => 1) } $class->ENCODED_FIELDS; foreach my $field (@fields) { next if defined &{"$class\::$field"}; if ($enc_fields{$field} and my $encoding = $class->ENCODING) { require Encode; *{"$class\::$field"} = sub { my ($self) = @_; return Encode::decode($encoding => $self->{struct}{$field}); }; *{"$class\::Set$field"} = sub { my ($self, $data) = @_; $self->{struct}{$field} = Encode::encode($encoding => $data); }; next; } *{"$class\::$field"} = sub { $_[0]->{struct}{$field} }; *{"$class\::Set$field"} = sub { $_[0]->{struct}{$field} = $_[1] }; } ${"$class\::init_done"} = 1; } sub initialize { return 1; } ### Miscellanous ### sub field { my ($self, $field) = @_; return $self->{struct}{$field}; } sub set_field { my ($self, $field, $data) = @_; $self->{struct}{$field} = $data; } sub classname { my ($self, $class) = @_; return undef unless $class; $class =~ s/__/::/g; my $base_class = $self->BASE_CLASS or return $class; return $base_class if $class eq '::BASE::'; return "$base_class\::$class"; } sub member_fields { return (); } sub dispatch_class { my ($self, $field) = @_; my $table = $DispatchTable{ref $self}; my $class = exists($table->{$field}) ? $table->{$field} : $table->{'*'}; $class = &$class($self, $field) if UNIVERSAL::isa($class, 'CODE'); defined $class or return; if (my $members = $self->{parent}{callback_members}) { return unless $members->{$class}; } my $subclass = $self->classname($class) or return; return if $subclass eq $class; return $subclass; } sub require { my ($class, $module) = @_; return unless defined $module; my $file = "$module.pm"; $file =~ s{::}{/}g; return $module if (eval { require $file; 1 }); die $@ unless $@ =~ /^Can't locate /; return; } sub require_class { my ($class, $subclass) = @_; return $class->require($class->classname($subclass)); } sub format_list { my ($self) = @_; return $self->FORMAT; } sub subformat_list { my ($self) = @_; $self->SUBFORMAT ? $self->SUBFORMAT : (); } sub default_args { my ($self) = @_; $self->DEFAULT_ARGS ? $self->DEFAULT_ARGS : (); } sub dispatch_table { my ($self) = @_; $self->DISPATCH_TABLE ? { $self->DISPATCH_TABLE } : {}; } sub delegate_subs { my ($self) = @_; $self->DELEGATE_SUBS ? { $self->DELEGATE_SUBS } : {}; } sub class { my ($self) = @_; return(ref($self) || $self); } sub make_formatter { my ($self, @formats) = @_; return Parse::Binary::FixedFormat->new( $self->make_format(@formats) ); } sub make_format { my ($self, @formats) = @_; return \@formats unless grep /\{/, @formats; my @prefix; foreach my $format (@formats) { last if $format =~ /\{/; push @prefix, $format; } return { Chooser => sub { $self->chooser(@_) }, Formats => [ \@prefix, \@formats ], }; } sub chooser { my ($self, $rec, $obj, $mode) = @_; my $idx = @{$obj->{Layouts}}; my @format = $self->eval_format($rec, @{$obj->{Formats}[1]}); $obj->{Layouts}[$idx] = $self->make_formatter(@format); return $idx; } sub eval_format { my ($self, $rec, @format) = @_; foreach my $key (sort keys %$rec) { s/\$$key\b/$rec->{$key}/ for @format; } !/\$/ and s/\{(.*?)\}/$1/eeg for @format; die $@ if $@; return @format; } sub padding { return ''; } sub load_struct { my ($self, $data) = @_; $self->{struct} = $Parser{ref $self}->unformat($$data . $self->padding, $self->{lazy}, $self); } sub load_size { my ($self, $data) = @_; $self->{size} = length($$data); return 1; } sub lazy_load { my ($self) = @_; ref(my $sub = $self->{lazy}) or return; $self->{lazy} = 1; $self->make_members unless $self->{iterator}; } my %DispatchClass; sub load { my ($self, $data, $attr) = @_; return $self unless defined $data; no strict 'refs'; my $class = ref($self) || $self; $class->init unless ${"$class\::init_done"}; $self->load_struct($data); $self->load_size($data); if (my $field = $DispatchField{$class}) { if ( my $subclass = $DispatchClass{$class}{ $self->{struct}{$field} } ||= $self->dispatch_class( $self->{struct}{$field}) ) { $self->require($subclass); bless($self, $subclass); $self->load($data, $attr); } } return $self; } my (%classname, %fill_cache); sub spawn { my ($self, %args) = @_; my $class = ref($self) || $self; no strict 'refs'; if (my $subclass = delete($args{Class})) { $class = $classname{$subclass} ||= do { my $name = $self->classname($subclass); $self->require($name); $name->init; $name; }; } bless({ struct => { %args, @{ $DefaultArgs{$class} }, %{ $fill_cache{$class} ||= $class->fill_in }, }, }, $class); } sub fill_in { my $class = shift; my $entries = {}; foreach my $super_class ($class->superclasses) { my $field = $DispatchField{$super_class} or next; my $table = $DispatchTable{$super_class} or next; foreach my $code (reverse sort keys %$table) { $class->is_type($table->{$code}) or next; $entries->{$field} = $code; last; } } return $entries; } sub spawn_sibling { my ($self, %args) = @_; my $parent = $self->{parent} or die "$self has no parent"; my $obj = $self->spawn(%args); @{$obj}{qw( lazy parent output siblings )} = @{$self}{qw( lazy parent output siblings )}; $obj->{size} = length($obj->dump); $obj->refresh_parent; $obj->initialize; return $obj; } sub sibling_index { my ($self, $obj) = @_; $obj ||= $self; my @siblings = @{$self->{siblings}}; foreach my $index (($obj->{index}||0) .. $#siblings) { return $index if $obj == $siblings[$index]; } return undef; } sub gone { my ($self, $obj) = @_; $self->{parent}{struct}{Data} .= ($obj || $self)->dump; } sub prepend_obj { my ($self, %args) = @_; if ($self->{lazy}) { my $obj = $self->spawn(%args); $self->gone($obj); return; } my $obj = $self->spawn_sibling(%args); my $siblings = $self->{siblings}; my $index = $self->{index} ? $self->{index}++ : $self->sibling_index; $obj->{index} = $index; splice(@$siblings, $index, 0, $obj); return $obj; } sub append_obj { my ($self, %args) = @_; my $obj = $self->spawn_sibling(%args); @{$self->{siblings}} = ( map { $_, (($_ == $self) ? $obj : ()) } @{$self->{siblings}} ); return $obj; } sub remove { my ($self, %args) = @_; my $siblings = $self->{siblings}; splice(@$siblings, $self->sibling_index, 1, undef); Scalar::Util::weaken($self->{parent}); Scalar::Util::weaken($self); } sub read_data { my ($self, $data) = @_; return undef unless defined $data; return \($data->dump) if UNIVERSAL::can($data, 'dump'); return $data if UNIVERSAL::isa($data, 'SCALAR'); return \($self->read_file($data)); } sub read_file { my ($self, $file) = @_; local *FH; local $/; open FH, "< $file" or die "Cannot open $file for reading: $!"; binmode(FH); return scalar ; } sub make_members { my ($self) = @_; $HasMembers{ref $self} or return; %{$self->{children}} = (); foreach my $field (@{$MemberFields{ref $self}}) { my ($format) = $self->eval_format( $self->{struct}, $FieldPackFormat{ref $self}{$field}, ); my $members = [ map { $self->new_member( $field, \pack($format, @$_) ) } $self->validate_memberdata($field) ]; $self->set_field_children( $field, $members ); } } sub set_members { my ($self, $field, $members) = @_; $field =~ s/:/_/g; $self->set_field_children( $field, [ map { $self->new_member( $field, $_ ) } @$members ], ); } sub set_field_children { my ($self, $field, $data) = @_; my $children = $self->field_children($field); @$children = @$data; return $children; } sub field_children { my ($self, $field) = @_; my $children = ($self->{children}{$field} ||= []); # $_->lazy_load for @$children; return(wantarray ? @$children : $children); } sub validate_memberdata { my ($self, $field) = @_; return @{$self->{struct}{$field}||[]}; } sub first_member { my ($self, $type) = @_; $self->lazy_load; return undef unless $HasMembers{ref $self}; no strict 'refs'; foreach my $field (@{$MemberFields{ref $self}}) { foreach my $member ($self->field_children($field)) { return $member if $member->is_type($type); } } return undef; } sub next_member { my ($self, $type) = @_; return undef unless $HasMembers{ref $self}; if ($self->{lazy} and !$self->{iterated}) { if (ref($self->{lazy})) { %{$self->{children}} = (); $self->{iterator} = $self->make_next_member; $self->lazy_load; } while (my $member = &{$self->{iterator}}) { return $member if $member->is_type($type); } $self->{iterated} = 1; return; } $self->{_next_member}{$type} ||= $self->members($type); shift(@{$self->{_next_member}{$type}}) || undef($self->{_next_member}{$type}); } sub make_next_member { my $self = shift; my $class = ref($self); my ($field_idx, $item_idx, $format) = (0, 0, undef); my @fields = @{$MemberFields{$class}}; my $struct = $self->{struct}; my $formats = $FieldPackFormat{$class}; sub { LOOP: { my $field = $fields[$field_idx] or return; my $items = $struct->{$field}; if ($item_idx > $#$items) { $field_idx++; $item_idx = 0; undef $format; redo; } $format ||= ($self->eval_format( $struct, $formats->{$field} ))[0]; my $item = $items->[$item_idx++]; $item = $item->($self, $items) if UNIVERSAL::isa($item, 'CODE'); $self->valid_memberdata($item) or redo; my $member = $self->new_member( $field, \pack($format, @$item) ); $member->{index} = (push @{$self->{children}{$field}}, $member) - 1; return $member; } }; } sub members { my ($self, $type) = @_; $self->lazy_load; no strict 'refs'; my @members = map { grep { $type ? $_->is_type($type) : 1 } $self->field_children($_) } @{$MemberFields{ref $self}}; wantarray ? @members : \@members; } sub members_recursive { my ($self, $type) = @_; my @members = ( ( $self->is_type($type) ? $self : () ), map { $_->members_recursive($type) } $self->members ); wantarray ? @members : \@members; } sub new_member { my ($self, $field, $data) = @_; my $obj = $MemberClass{ref $self}{$field}->new( $data, { lazy => $self->{lazy}, parent => $self } ); $obj->{output} = $self->{output}; $obj->{siblings} = $self->{children}{$field}||=[]; $obj->initialize; return $obj; } sub valid_memberdata { length($_[-1][0]) } sub dump_members { my ($self) = @_; return $Packer{ref $self}->format($self->{struct}); } sub dump { my ($self) = @_; return $self->dump_members if $HasMembers{ref $self}; return $Packer{ref $self}->format($self->{struct}); } sub write { my ($self, $file) = @_; if (ref($file)) { $$file = $self->dump; } elsif (!defined($file) and my $fh = $self->{output}) { print $fh $self->dump; } else { $file = $self->{filename} unless defined $file; $self->write_file($file, $self->dump) if defined $file; } } sub write_file { my ($self, $file, $data) = @_; local *FH; open FH, "> $file" or die "Cannot open $file for writing: $!"; binmode(FH); print FH $data; }; sub superclasses { my ($self) = @_; my $class = $self->class; no strict 'refs'; return @{"$class\::ISA"}; } my %type_cache; sub is_type { my ($self, $type) = @_; return 1 unless defined $type; my $class = ref($self) || $self; if (exists $type_cache{$class}{$type}) { return $type_cache{$class}{$type}; } $type_cache{$class}{$type} = 1; $type =~ s/__/::/g; $type =~ s/[^\w:]//g; return 1 if ($class =~ /::$type$/); no strict 'refs'; foreach my $super_class ($class->superclasses) { return 1 if $super_class->is_type($type); }; $type_cache{$class}{$type} = 0; } sub refresh { my ($self) = @_; foreach my $field (@{$MemberFields{ref $self}}) { my $parser = $self->field_parser($field); my $padding = $self->padding; local $SIG{__WARN__} = sub {}; @{$self->{struct}{$field}} = map { $parser->unformat( $_->dump . $padding, 0, $self)->{$field}[0] } grep defined, @{$self->{children}{$field}||[]}; $self->validate_memberdata; } $self->refresh_parent; } sub refresh_parent { my ($self) = @_; my $parent = $self->{parent} or return; $parent->refresh unless !Scalar::Util::blessed($parent) or $parent->{lazy}; } sub first_parent { my ($self, $type) = @_; return $self if $self->is_type($type); my $parent = $self->{parent} or return; return $parent->first_parent($type); } sub substr { my $self = shift; my $data = $self->Data; my $offset = shift(@_) - ($self->{size} - length($data)); my $length = @_ ? shift(@_) : (length($data) - $offset); my $replace = shift; # XXX - Check for "substr outside string" return if $offset > length($data); # Fetch a range return substr($data, $offset, $length) if !defined $replace; # Substitute a range substr($data, $offset, $length, $replace); $self->{struct}{Data} = $data; } sub set_output_file { my ($self, $file) = @_; open my $fh, '>', $file or die $!; binmode($fh); $self->{output} = $fh; } my %callback_map; sub callback { my $self = shift; my $pkg = shift || caller; my $types = shift or return; my $map = $callback_map{"@$types"} ||= $self->callback_map($pkg, $types); my $sub = $map->{ref $self} || $map->{'*'} or return; unshift @_, $self; goto &$sub; } sub callback_map { my ($self, $pkg, $types) = @_; my %map; my $base = $self->BASE_CLASS; foreach my $type (map "$_", @$types) { no strict 'refs'; my $method = $type; $method =~ s/::/_/g; $method =~ s/\*/__/g; defined &{"$pkg\::$method"} or next; $type = "$base\::$type" unless $type eq '*'; $map{$type} = \&{"$pkg\::$method"}; } return \%map; } sub callback_members { my $self = shift; $self->{callback_members} = { map { ($_ => 1) } @{$_[0]} }; while (my $member = $self->next_member) { $member->callback(scalar caller, @_); } } sub done { my $self = shift; return unless $self->{lazy}; $self->write; $self->remove; } 1; __END__ =head1 AUTHORS Audrey Tang Ecpan@audreyt.orgE =head1 COPYRIGHT Copyright 2004-2009 by Audrey Tang Ecpan@audreyt.orgE. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut Parse-Binary-0.11/Makefile.PL0000644000076500007650000000024011136665517015636 0ustar audreytaudreyt#!/usr/bin/perl use strict; use inc::Module::Install; name 'Parse-Binary'; all_from 'lib/Parse/Binary.pm'; recommends 'Scalar::Util'; sign; WriteAll; Parse-Binary-0.11/MANIFEST0000644000076500007650000000064611136665431015022 0ustar audreytaudreytArtistic Changes COPYING inc/Module/Install.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/Parse/Binary.pm lib/Parse/Binary/FixedFormat.pm lib/Parse/Binary/FixedFormat/Variants.pm Makefile.PL MANIFEST This list of files META.yml README SIGNATURE t/1-basic.t Parse-Binary-0.11/META.yml0000644000076500007650000000041410441603236015124 0ustar audreytaudreytabstract: Binary data structure parser author: Audrey Tang distribution_type: module generated_by: Module::Install version 0.63 license: perl name: Parse-Binary no_index: directory: - inc - t recommends: Scalar::Util: 0 version: 0.10 Parse-Binary-0.11/README0000644000076500007650000000342611136664117014550 0ustar audreytaudreytThis is the README file for Parse::Binary, a module for unpacking binary data structures into object hierarchies. Please type "perldoc Parse::Binary" after installation to see the module usage information. * Installation Parse::Binary uses the standard perl module install process: cpansign -v # optional; see SIGNATURE for details perl Makefile.PL make # or 'nmake' on Win32 make test make install * Copyright The Parse::Binary module is under the following license: Copyright 2004-2009 by Audrey Tang . This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. (See the "Artistic" file included in this distribution.) * Copyright for derived works Two modules included in this distribution, Parse::Binary::FixedFormat and Parse::Binary::FixedFormat::Variants, are derived from the Data::FixedFormat module, also available from CPAN. They are under the following license: Copyright 2004-2009 by Audrey Tang . Copyright (C) 2000,2002 Thomas Pfau. All rights reserved. This module is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. (See the "COPYING" file included in this distribution.) Parse-Binary-0.11/SIGNATURE0000644000076500007650000000370111136665653015156 0ustar audreytaudreytThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.55. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 7a95fc8778fbce1f60d222e0d0d1dbb6c649461f Artistic SHA1 17e3b0eea99abffe6ac71e65627413236e0b117a COPYING SHA1 eaa39b7294f4189c42355e2a6c501798ed038c62 Changes SHA1 c2329e0e5dbb9b0567c98deac06688f9ea17fbb1 MANIFEST SHA1 b403a8a7e87ed9ceef03e93f747cc63a4988cc96 META.yml SHA1 26b4455b0c4060bc6d581a8f618e75d9afe7a2fa Makefile.PL SHA1 8c4091e2ca8e1d5e7ef521e5aae3a9b2b672e56c README SHA1 5c9e093b0facca46d50e3c69d5569aa7a98db0b8 inc/Module/Install.pm SHA1 465acb50b9006ce61f58a7bd02d0bb029ddceaa6 inc/Module/Install/Base.pm SHA1 8356d82167fc00550b4a3ceea8bd852a374d7509 inc/Module/Install/Can.pm SHA1 b47ce07fa6d6e38e3daa6cfc752b23f59a64754c inc/Module/Install/Fetch.pm SHA1 37ed4ccd7aba10119e6f2993b8082674ce2e5961 inc/Module/Install/Makefile.pm SHA1 4aa1c578faad51f31e62bed7b28d3d42b88219c3 inc/Module/Install/Metadata.pm SHA1 d7529d795a1304c88253b26a9089913edf31ae5e inc/Module/Install/Win32.pm SHA1 2a74aba5a78e7ab2776382e42106ebe941c2ac28 inc/Module/Install/WriteAll.pm SHA1 1e0e6e276b09e4c77c05c3c92e1fc0c5a716558f lib/Parse/Binary.pm SHA1 ce549daa9815134dfc71d4f4cfe1a1cf3e8c5478 lib/Parse/Binary/FixedFormat.pm SHA1 5a0fddf988b8560d2c01baedbcadc59b1e64d922 lib/Parse/Binary/FixedFormat/Variants.pm SHA1 bfadcd7e4941dce962d9d5e67311bb04bd96406f t/1-basic.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (Darwin) iD8DBQFJe2urtLPdNzw1AaARAk3gAJ9Aom7EANiPKiYV4TlOHQpPn1zV8wCfd3M+ Rrq1g8/7XGADxnG+nuIkZWw= =3nA6 -----END PGP SIGNATURE----- Parse-Binary-0.11/t/0000755000076500007650000000000011136665651014132 5ustar audreytaudreytParse-Binary-0.11/t/1-basic.t0000644000076500007650000000011710163031057015517 0ustar audreytaudreytuse strict; use Test; BEGIN { plan tests => 1 } use Parse::Binary; ok(1); 1;