#!/usr/bin/perl -w use strict; use Message::Util::QName::Filter { d => q, dis2pm => q, DOMCore => q, DOMMain => q, lang => q, Perl => q, license => q, ManakaiDOM => q, owl => q, rdf => q, rdfs => q, }; use Getopt::Long; use Pod::Usage; my %Opt; GetOptions ( 'for=s' => \$Opt{For}, 'help' => \$Opt{help}, 'verbose!' => $Opt{verbose}, ) or pod2usage (2); if ($Opt{help}) { pod2usage (0); exit; } $Opt{file_name} = shift; BEGIN { require 'manakai/genlib.pl'; require 'manakai/dis.pl'; } our $State; our $result = ''; eval q{ sub impl_msg ($;%) { warn shift () . "\n"; } } unless $Opt{verbose}; sub perl_change_package (%) { my %opt = @_; my $fn = $opt{full_name}; unless ($fn eq $State->{ExpandedURI q}) { $State->{ExpandedURI q} = $fn; return perl_statement qq; } else { return ''; } } # perl_change_package $State->{DefaultFor} = $Opt{For}; my $source = dis_load_module_file (module_file_name => $Opt{file_name}, For => $Opt{For}, use_default_for => 1); $State->{for_def_required}->{$State->{DefaultFor}} ||= 1; dis_check_undef_type_and_for () unless $Opt{no_undef_check}; if (dis_uri_for_match (ExpandedURI q, $State->{DefaultFor})) { dis_perl_init ($source, For => $State->{DefaultFor}); } $State->{ExpandedURI q} = 'main'; $result .= "#!/usr/bin/perl \n"; $result .= perl_comment q . "\n" . q<"> . $Opt{file_name} . q<" at > . rfc3339_date (time) . qq<.\n> . q; $result .= perl_statement q; $result .= perl_change_package (full_name => $State->{Module}->{$State->{module}} ->{ExpandedURI q}); $result .= perl_statement perl_assign perl_var (type => '$', local_name => 'VERSION', scope => 'our') => perl_literal version_date time; for my $pack (values %{$State->{Module}->{$State->{module}} ->{ExpandedURI q}||{}}) { next unless defined $pack->{Name}; if ({ ExpandedURI q => 1, ExpandedURI q => 1, ExpandedURI q => 1, ExpandedURI q => 1, ExpandedURI q => 1, }->{$pack->{ExpandedURI q}}) { ## Package name and version $result .= perl_change_package (full_name => $pack->{ExpandedURI q}); $result .= perl_statement perl_assign perl_var (type => '$', local_name => 'VERSION', scope => 'our') => perl_literal version_date time; ## Inheritance my @isa; for my $uri (@{$pack->{ISA}||[]}, @{$pack->{Implement}||[]}) { my $pack = $State->{Type}->{$uri}; if (defined $pack->{ExpandedURI q}) { push @isa, $pack->{ExpandedURI q}; } else { impl_msg ("Inheriting package name for <$uri> not defined", node => $pack->{src}) if $Opt{verbose}; } } $result .= perl_inherit \@isa; ## Members if ({ ExpandedURI q => 1, ExpandedURI q => 1, ExpandedURI q => 1, }->{$pack->{ExpandedURI q}}) { for my $method (values %{$pack->{ExpandedURI q}}) { next unless defined $method->{Name}; if ($method->{ExpandedURI q} eq ExpandedURI q) { $result .= perl_sub (name => $method->{ExpandedURI q}, code => ''); } elsif ($method->{ExpandedURI q} eq ExpandedURI q) { $result .= perl_sub (name => $method->{ExpandedURI q}, 'prototype' => (defined $method->{ExpandedURI q} ->{Name} ? '$;$' : '$'), code => ''); } } # package method ## TODO: Const } ## TODO: Const } # root object } ## Export if (keys %{$State->{perl_primary_module}->{perl_export_ok}||{}}) { $result .= perl_change_package full_name => $State->{perl_primary_module}->{perl_package_name}; $result .= perl_statement 'require Exporter'; $result .= perl_inherit ['Exporter']; $result .= perl_statement perl_assign perl_var (type => '@', scope => 'our', local_name => 'EXPORT_OK') => '(' . perl_list (keys %{$State->{perl_primary_module} ->{perl_export_ok}}) . ')'; if (keys %{$State->{perl_primary_module}->{perl_export_tags}||{}}) { $result .= perl_statement perl_assign perl_var (type => '%', scope => 'our', local_name => 'EXPORT_TAGS') => '(' . perl_list (map { $_ => [keys %{$State->{perl_primary_module} ->{perl_export_tags}->{$_}}] } keys %{$State->{perl_primary_module} ->{perl_export_tags}}) . ')'; } } $result .= perl_statement 1; output_result $result; 1;