#!/usr/bin/perl -w

use strict;
use warnings;

use POD::Find;
use POD::POM;

my $localized_perldiag = $ARGV[0];

die "No perldiag specified" unless $localized_perldiag;

my $localized_pod_filename = Pod::Find::pod_where({-inc => 1}, $localized_perldiag);
my $default_pod_filename = Pod::Find::pod_where({-inc => 1}, 'perldiag');

my $parser = Pod::POM->new();
my $pom_local = $parser->parse_file($localized_pod_filename);
if (!$pom_local) {
	die "Could not parse localized perldiag: " . $parser->error();
}

my $pom_default = $parser->parse_file($default_pod_filename);
if (!$pom_default) {
	die "Could not parse default perldiag: " . $parser->error();
}

my (@local_errors, @default_errors);
foreach my $item ($pom_local->head1->[1]->over->[0]->item) {
	push @local_errors, $item->title;
}

foreach my $item ($pom_default->head1->[1]->over->[0]->item) {
	push @default_errors, $item->title;
}

if ($#local_errors != $#default_errors) {
	print "Unequal number of errors: localized - $#local_errors, default - $#default_errors.\n";
}

for (my $i = 0; $i <= $#local_errors; $i++) {
	if ($local_errors[$i] ne $default_errors[$i]) {
		print 'Got: "' . $local_errors[$i] . '", expected: "' . $default_errors[$i] . '".' . "\n";
	}
}

__END__

=head1 NAME

check_perldiag - check a localized version of L<peldiag> for consistency

=head1 SYNOPSIS

From the command line:

	check_perldiag POD2::FR::perldiag

=head1 DESCRIPTION

This script compares a translated version of L<peldiag> with the default L<peldiag> installed with perl. It compares each error message in the two files and tells you if they do not match. A warning is issued if the two files contain a different number of error messages defined.

=head1 AUTHOR

Petar Shangov, C<< <pshangov at yahoo.com> >>

=head1 COPYRIGHT & LICENSE

Copyright 2008 Petar Shangov, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


