4 use YAML::Syck qw(LoadFile);
 
  12 locale-diff - Compare two YAML files and print how their datastructures differ
 
  16     locale-diff en.yml is.yml
 
  17     locale-diff en.yml is.yml | grep '*'
 
  21 This utility prints the differences between two YAML files using
 
  22 L<Test::Differences>. The purpose of it is to diff the files is
 
  23 F<config/locales> to find out what keys need to be added to the
 
  24 translated files when F<en.yml> changes.
 
  32 Print this help message.
 
  38 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@f-prot.com>
 
  42 # Get the command-line options
 
  43 Getopt::Long::Parser->new(
 
  44     config => [ qw< bundling no_ignore_case no_require_order pass_through > ],
 
  46     'h|help' => \my $help,
 
  52 # If we're not given two .yml files
 
  53 help() if @ARGV != 2 or (!-f $ARGV[0] or !-f $ARGV[1]);
 
  55 my ($from, $to) = @ARGV;
 
  57 my $from_data = LoadFile($from);
 
  58 my $to_data   = LoadFile($to);
 
  60 # Normalize the two to have the same root element
 
  61 my ($from_key) = keys %$from_data;
 
  62 $from_data = $from_data->{$from_key};
 
  64 my ($to_key) = keys %$to_data;
 
  65 $to_data = $to_data->{$to_key};
 
  68 walkdepth \&delete_hash_values, $_ for $from_data, $to_data;
 
  70 # Hack around Test::Differences wanting a Test::* module loaded
 
  72 sub Test::ok { print shift }
 
  75 eq_or_diff($from_data, $to_data);
 
  77 sub delete_hash_values
 
  79     return unless defined $Data::Walk::type and $Data::Walk::type eq 'HASH';
 
  81     # We totally need Perl 6's $OUTER::_ to make this prettier
 
  84     @$hash{grep { not ref $hash->{$_} } keys %$hash} = ();
 
  91     Pod::Usage::pod2usage(
 
  92         -verbose => $arg{ verbose },
 
  93         -exitval => $arg{ exitval } || 0,