title: Perl reading zip files with IO::Uncompress::AnyUncompress
body: <p>We are moving from our current build system (which is a mess) to one that uses Ant with Ivy. I'm cleaning up all the build files, and finding the jar dependencies. I thought it might be easier if I could automate it a bit, by going through the jars that are checked into the project, finding what classes they contain, then matching those classes with the various <code>import</code> statements in the Java code.</p>
  <p>I have used <code>Archive::Tar</code> before, but <code>Archive::Zip</code> isn't a standard Perl module. (My concern is that someone is going to try my script, call me in the middle of the night and tell me it isn't working.)</p>
  <p>I noticed that <code>IO::Uncompress::AnyUncompress is a standard module, so I thought I could try </code>IO::Uncompress::AnyUncompress<code>or at least</code>IO::Uncompress::Unzip` which is also a standard module.</p>
  <p>Unfortunately, the documentation for these modules give no examples (According to the documentation, examples are a <em>todo</em>).</p>
  <p>I'm able to successfully open my jar and create an object:</p>
  <pre><code> my $zip_obj = IO::Uncompress::AnyUncompress-&gt;new ( $zip_file );
  </code></pre>
  <p>Now, I want to see the contents. According to the documentation:</p>
  <h3>getHeaderInfo</h3>
  <blockquote>
  <p>Usage is</p>
  </blockquote>
  <pre><code>$hdr  = $z-&gt;getHeaderInfo();
  @hdrs = $z-&gt;getHeaderInfo();
  </code></pre>
  <blockquote>
  <p>This method returns either a hash reference (in scalar context) or a list or hash references (in array context) that contains information about each of the header fields in the compressed data stream(s).</p>
  </blockquote>
  <p>Okay, this isn't an object like <code>Archive::Tar</code> or <code>Archive::Zip</code> returns, and there are no methods or subroutines mentioned to parse the data. I'll use <code>Data::Dumper</code> and see what hash keys are contained in the reference.</p>
  <p>Here's a simple test program:</p>
  <pre><code>#! /usr/bin/env perl
  use 5.12.0;
  use warnings;
  
  use IO::Uncompress::AnyUncompress;
  use Data::Dumper;
  
  my $obj = IO::Uncompress::AnyUncompress-&gt;new(&quot;testng.jar&quot;)
  
      or die qq(You're an utter failure);
  
  say qq(Dump of \$obj = ) . Dumper $obj;
  
  my @header2 = $obj-&gt;getHeaderInfo;
  say qq(Dump of \$header = ) . Dumper $headers-&gt;[0];
  </code></pre>
  <p>And here's my results:</p>
  <pre><code>Dump of $obj = $VAR1 = bless( \*Symbol::GEN0, 'IO::Uncompress::Unzip' );
  
  Dump of $header = $VAR1 = {
            'UncompressedLength' =&gt; 0,
            'Zip64' =&gt; 0,
            'MethodName' =&gt; 'Stored',
            'Stream' =&gt; 0,
            'Time' =&gt; 1181224440,
            'MethodID' =&gt; 0,
            'CRC32' =&gt; 0,
            'HeaderLength' =&gt; 43,
            'ExtraFieldRaw' =&gt; '¦-  ',
            'ExtraField' =&gt; [
                              [
                                '¦-',
                                ''
                              ]
                            ],
            'FingerprintLength' =&gt; 4,
            'Type' =&gt; 'zip',
            'TrailerLength' =&gt; 0,
            'CompressedLength' =&gt; 0,
            'Name' =&gt; 'META-INF/',
            'Header' =&gt; 'PK
       +N¦6                 META-INF/¦-  '
          };
  </code></pre>
  <p>Some of that looks sort of useful. However, all of my entries return `'Name' =&gt; 'META-INF/``, so it doesn't look like a file name.</p>
  <p>Is it possible to use <code>IO::Uncompress::AnyUncompress</code> (or even <code>IO::Uncompress:Unzip</code>) to read through the archive and see what files are in its contents. And, if so, how do I parse that header?</p>
  <p>Otherwise, I'll have to go with <code>Archive::Zip</code> and let people know they have to download and install it from CPAN on their systems.</p>