#!perl
use strict;
use warnings FATAL => 'all';
use diagnostics;
use MarpaX::Languages::IDL::AST;
use Getopt::Long;
use Pod::Usage;
use POSIX qw/EXIT_FAILURE EXIT_SUCCESS/;
use IO::String;

# ABSTRACT: IDL to perl's Moose translation

our $VERSION = '0.001'; # VERSION

# PODNAME: idl2moose

my $help = 0;
my $input = undef;
my $output = undef;
my $nativeFloat = 1;

GetOptions ('help!' => \$help,
            'input=s' => \$input,
            'output=s' => \$output,
            'nativeFloat!' => \$nativeFloat);

if ($help || ! $input) {
    my $pod = do {local $/; <DATA>};
    my $podfh = IO::String->new($pod);
    pod2usage(-verbose => 2, -noperldoc => 1, -input => $podfh, -exitval => $help ? EXIT_SUCCESS : EXIT_FAILURE);
}

my $obj = MarpaX::Languages::IDL::AST->new();
my $r = $obj->parse($input);
my $result = $r->generate()->output();

if ($output) {
    open(OUTPUT, '>', $output) || die "Cannot open $output, $!";
    print $output $result;
    close(OUTPUT) || warn "Cannot close $output, $!";
} else {
    print $result;
}

exit(EXIT_SUCCESS);

=pod

=encoding utf-8

=head1 NAME

idl2moose - IDL to perl's Moose translation

=head1 VERSION

version 0.001

=head1 AUTHOR

Jean-Damien Durand <jeandamiendurand@free.fr>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Jean-Damien Durand.

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

=cut

__DATA__

# --------------------------------------------------------------------------------------

=head1 NAME

idl2moose - IDL to perl's Moose translation

=head1 SYNOPSIS

 idl2moose [options]

=head1 OPTIONS

=over 8

=item B<--help>

This help

=item B<--input <filename>>

Input IDL filename.

=item B<--output <filename>>

Output filename. Default to STDOUT.

=item B<--nativeFloat>

Use of native floats. A false value will force Math::BigFloat. Default to a true value.

=back

=head1 EXAMPLES

 idl2moose dom.idl > dom.pm

=head1 SEE ALSO

L<MarpaX::Languages::IDL::AST>
