#!/usr/bin/perl ## ## snapdiff -- Compare the contents of two CPAN.pm autobundle snapshot ## files for differing versions ## ## Mike Fletcher <fletch+perl@phydeaux.org> ## use strict; use Pod::Parser; { ## Define a Pod::Parser subclass that pulls version information out ## of the autobundle file package MyParser; our @ISA = qw( Pod::Parser ); ## command -- note when we see `=head1 CONTENTS' sub command { my ($parser, $command, $paragraph, $line_num) = @_; if( $command eq 'head1' and $paragraph =~ /CONTENTS/ ) { $parser->{in_contents} = 1; } else { $parser->{in_contents} = undef; } } ## textblock -- Pull out module/version pairs if we're inside a ## CONTENTS section sub textblock { my( $parser, $para, $line_num ) = @_; ## Ignore text if we haven't seen a `=head1 CONTENTS' command return unless $parser->{in_contents}; $para =~ /(\S+)\s+(\S+)/; $parser->{results}->{$1} = $2; } } ## back in package main main ## Check that we're given two filenames die "usage: $0 snap1 snap2\n" unless @ARGV == 2; my( $snap1, $snap2 ) = @ARGV; ## Create some hashes to hold the results for each file my $results = { $snap1 => {}, $snap2 => {}, }; ## To track mismatched versions that we've already seen my %mismatch; ## Parse out the bundle contents from each file foreach( $snap1, $snap2 ) { local( *IN ); open( IN, $_ ) or die "Error opening $_: $!\n"; ## Create new MyParser, passing it the hashref to store results into ## for the file in question my $p = MyParser->new( results => $results->{$_} ); $p->parse_from_filehandle( \*IN ); close( IN ); } print "$snap1 vs $snap2\n"; cmp_hashes( $results->{$snap1}, $results->{$snap2}, \%mismatch ); print "\n\n$snap2 vs $snap1\n"; cmp_hashes( $results->{$snap2}, $results->{$snap1}, \%mismatch ); exit 0; ## ## cmp_hashes -- Compare contents of hash $ha to hash $hb. $mismatch ## contains keys we already know don't match ## sub cmp_hashes { my( $ha, $hb, $mismatch ) = @_; foreach( sort keys %{ $ha } ) { ## format a nice, space justified version of name for printing my $name = sprintf "%-35s", $_; unless( exists $hb->{$_} ) { ## it exists in hash a but not b print "$name ver ", $ha->{$_}, " only here\n"; } else { ## If they're not equal and we don't know about the mismatch ## already then gripe about it (and make note of the fact) if( $ha->{$_} ne $hb->{$_} and not $mismatch->{$_} ) { print "$name here ver ", $ha->{$_}, " there ver ", $hb->{$_}, "\n" +; $mismatch->{$_}++; # note that there was a mismatch } } } } __END__

In reply to snapdiff -- Compare CPAN autobundle files by Fletch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.