
# Update the versions from Subversion
use Cwd qw(abs_path);
use File::Basename;
use File::Find;

# Get the current path and revision
my $file    = abs_path($0);
my $path    = dirname($file);
my $svninfo = `svn info $file | grep Revision`;
our $version = '';

if ( $svninfo and !$ARGV[0] )
{
    my $rev = ( $svninfo =~ /Revision: ([0-9]*)/ )[0];

    $version = "D1-r" . $rev;

    # Find all pm, pl, xml, xsl and xsd files
    find( { wanted => \&do_version }, $path );

}

use ExtUtils::MakeMaker;

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    NAME         => 'Zymonic',
    VERSION_FROM => 'lib/Zymonic/Base.pm',                                   # finds \$VERSION
    AUTHOR       => 'Alex Masidlover et al. (alex.masidlover@zednax.com)',
    ABSTRACT     => 'Zymonic Workflow System',
    PREREQ_PM    => {
        'Test::Taint'                => 0,                                   # License as Perl
        'Test::More'                 => 0,                                   # License as Perl
        'Test::Deep'                 => 0,                                   # License as Perl
        'XML::Simple'                => 0,                                   # License as Perl
        'Data::Dumper'               => 0,                                   # License as Perl
        'Data::Structure::Util'      => 0,                                   # License as Perl
        'DBI'                        => 1.19,                                # License as Perl
        'CGI::Pretty'                => 0,                                   # License as Perl
        'Unicode::UCD'               => 0,                                   # License as Perl
        'Unix::Syslog'               => 0,                                   # License as Perl
        'Net::LDAP'                  => 0,                                   # License as Perl
        'Net::LDAP::Schema'          => 0,                                   # License as Perl
        'POSIX'                      => 0,                                   # License as Perl
        'MIME::Lite'                 => 0,                                   # License as Perl
        'Exception::Class'           => 0,                                   # License as Perl
        'File::Find'                 => 0,                                   # License as Perl
        'Cwd'                        => 0,                                   # License as Perl
        'File::Basename'             => 0,                                   # License as Perl
        'Clone'                      => 0,                                   # License as Perl
        'File::Touch'                => 0,                                   # License as Perl
        'URI::Escape'                => 0,                                   # License as Perl
        'Business::CreditCard'       => 0,                                   # License as Perl
        'HTML::Entities'             => 0,                                   # License as Perl
        'Date::Calc'                 => 0,                                   # License as Perl
        'Date::Calc::XS'             => 0,                                   # License as Perl
        'Date::Business'             => 0,                                   # License as Perl
        'Locale::Currency::Format'   => 0,                                   # License as Perl
        'DateTime::Format::Strptime' => 0,                                   # License as Perl
        'DateTime'                   => 0,                                   # License as Perl
        'Zymonic::Client'            => 0,                                   # License as Perl
        'Date::Parse'                => 0,                                   # License as Perl
        'Encode'                     => 0,                                   # License as Perl
        'Time::Piece'                => 0,                                   # License as Perl
        'Text::CSV::Encoded'         => 0,                                   # License as Perl
        'POSIX::strptime'            => 0,                                   # License as Perl
        'GraphViz'                   => 0,                                   # License as Perl
        'IPC::ShareLite'             => 0,                                   # License as Perl
        'Storable'                   => 0,                                   # License as Perl
        'Scalar::Util'               => 0,                                   # License as Perl
        'Locale::Currency'           => 0,                                   # License as Perl
        'Locale::Country'            => 0,                                   # License as Perl
        'Time::Local'                => 0,                                   # License as Perl
        'Mail::Sendmail'             => 0,                                   # License as Perl
        'Crypt::OpenSSL::AES'        => 0,                                   # License as Perl
        'File::Copy'                 => 0,                                   # License as Perl
        'File::Basename'             => 0,                                   # License as Perl
        'File::Path'                 => 0,                                   # License as Perl
        'Expect'                     => 0,                                   # License as Perl
        'Algorithm::FloodControl'    => 0,                                   # License as Perl
        'IO::Socket'                 => 0,                                   # License as Perl
        'Taint::Util'                => 0,                                   # License as Perl
        'XML::XPath'                 => 0,                                   # License as Perl
        'File::Slurp'                => 0,                                   # License as Perl
        'Digest::SHA'                => 0,                                   # License as Perl
        'Date::Manip::TZ'            => 0,                                   # License as Perl
    },
);

# callback to do the tidying.
sub do_version
{
    my $file = $File::Find::name;

    return unless $file =~ /\.pm$/;

    open( FILE, "+<" . $file );

    my @lines = <FILE>;

    seek FILE, 0, 0;

    foreach my $line (@lines)
    {
        $line =~ s/VERSION\s*=\s*'.*'/VERSION = '$main::version'/g;
        print FILE $line;
    }
    close FILE;
}
