Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^5: UML to Perl

by Anonymous Monk
on Jul 29, 2011 at 12:40 UTC ( [id://917460]=note: print w/replies, xml ) Need Help??


in reply to Re^4: UML to Perl
in thread UML to Perl

In any case, I'm not sure how truly helpful this tip was, UMMF has a few portability related bugs, it won't work out of the box on win32

With this patch the examples will work (generate code files)

To apply patch

cd UMMF-1.02
patch -p1 < path/to/patchfile 
diff -ru UMMF-1.02/bin/files2dirs UMMF-1.02-new5/bin/files2dirs --- UMMF-1.02/bin/files2dirs 2006-05-13 18:40:03.000000000 -0700 +++ UMMF-1.02-new5/bin/files2dirs 2011-07-29 04:45:09.609375000 -07 +00 @@ -117,6 +117,7 @@ while ( @ARGV ) { local $_ = shift @ARGV; + next unless length $_; if ( $_ eq '-' ) { push(@input_files, $_); } diff -ru UMMF-1.02/bin/files2dirs.pl UMMF-1.02-new5/bin/files2dirs.pl --- UMMF-1.02/bin/files2dirs.pl 2006-05-13 18:40:03.000000000 -0700 +++ UMMF-1.02-new5/bin/files2dirs.pl 2011-07-29 04:45:20.875000000 +-0700 @@ -117,6 +117,7 @@ while ( @ARGV ) { local $_ = shift @ARGV; + next unless length $_; if ( $_ eq '-' ) { push(@input_files, $_); } diff -ru UMMF-1.02/bin/ummf UMMF-1.02-new5/bin/ummf --- UMMF-1.02/bin/ummf 2006-05-13 18:40:03.000000000 -0700 +++ UMMF-1.02-new5/bin/ummf 2011-07-29 04:41:24.281250000 -0700 @@ -155,7 +155,7 @@ ##################################################################### +## -use File::Path; +use File::Path qw[ make_path ]; use IO::Handle; use IO::Pipe; @@ -337,11 +337,16 @@ if ( $output eq '-' ) { $output_h = \*STDOUT; } else { - mkpath($output); + my $err; + make_path( $output, { verbose => 1, error => \$err }); + if( @$err ){ print STDERR " make_path failed : @{[%$_]} \n" for + @$err } + $output_h = new IO::Pipe; - my $cmd = "$_0dir/files2dirs $file2dirs_opts -d '$output' -"; - $output_h->writer($cmd) || die("Cannot pipe to 'cmd': $!"); - # print STDERR "Output to '$cmd'\n"; +#~ my $cmd = "$^X $_0dir/files2dirs $file2dirs_opts -d '$output +' -"; + my @cmd = ( $^X , "$_0dir/files2dirs", $file2dirs_opts, '-d', + $output, '-' ); +#~ local $" = ' '; + $output_h->writer(@cmd) || die("Cannot pipe to 'cmd': $!"); + print STDERR "$output_h Output to >> @cmd <<\n"; } } } @@ -350,7 +355,18 @@ sub close_output { if ( $output_h ) { - $output_h->close() unless $output_h eq \*STDOUT; + if( $output_h != \*STDOUT ){ + print STDERR "Trying to close $output_h \n"; + if( $^O ne 'MSWin32' ){ + $output_h -> close(); # hangs?? + } else { + $output_h -> IO::Pipe::End::SUPER::close() for 1 .. 5; + print STDERR " done ->SUPER::close() killing\n"; + kill 9, ${*$output_h}{'io_pipe_pid'} for 1 .. 3; + print STDERR " done killing \n"; + } + } + $output_h = undef; } } @@ -406,9 +422,10 @@ elsif ( $input =~ /\.(zargo|zuml)$/i ) { # $DB::single = 1; my $fh = IO::Pipe->new(); - my @cmd = ( "$basedir/bin/uml2xmi", $input ); + my @cmd = ( $^X, "$basedir/bin/uml2xmi", $input ); { - local $" = ' '; +#~ local $" = ' '; + print STDERR "IO::Pipe ummi >> @cmd << \n"; $fh->reader(@cmd) || die("Cannot run '@cmd': $!"); } diff -ru UMMF-1.02/bin/ummf.pl UMMF-1.02-new5/bin/ummf.pl --- UMMF-1.02/bin/ummf.pl 2006-05-13 18:40:03.000000000 -0700 +++ UMMF-1.02-new5/bin/ummf.pl 2011-07-29 04:41:25.984375000 -0700 @@ -155,7 +155,7 @@ ##################################################################### +## -use File::Path; +use File::Path qw[ make_path ]; use IO::Handle; use IO::Pipe; @@ -337,11 +337,16 @@ if ( $output eq '-' ) { $output_h = \*STDOUT; } else { - mkpath($output); + my $err; + make_path( $output, { verbose => 1, error => \$err }); + if( @$err ){ print STDERR " make_path failed : @{[%$_]} \n" for + @$err } + $output_h = new IO::Pipe; - my $cmd = "$_0dir/files2dirs $file2dirs_opts -d '$output' -"; - $output_h->writer($cmd) || die("Cannot pipe to 'cmd': $!"); - # print STDERR "Output to '$cmd'\n"; +#~ my $cmd = "$^X $_0dir/files2dirs $file2dirs_opts -d '$output +' -"; + my @cmd = ( $^X , "$_0dir/files2dirs", $file2dirs_opts, '-d', + $output, '-' ); +#~ local $" = ' '; + $output_h->writer(@cmd) || die("Cannot pipe to 'cmd': $!"); + print STDERR "$output_h Output to >> @cmd <<\n"; } } } @@ -350,7 +355,18 @@ sub close_output { if ( $output_h ) { - $output_h->close() unless $output_h eq \*STDOUT; + if( $output_h != \*STDOUT ){ + print STDERR "Trying to close $output_h \n"; + if( $^O ne 'MSWin32' ){ + $output_h -> close(); # hangs?? + } else { + $output_h -> IO::Pipe::End::SUPER::close() for 1 .. 5; + print STDERR " done ->SUPER::close() killing\n"; + kill 9, ${*$output_h}{'io_pipe_pid'} for 1 .. 3; + print STDERR " done killing \n"; + } + } + $output_h = undef; } } @@ -406,9 +422,10 @@ elsif ( $input =~ /\.(zargo|zuml)$/i ) { # $DB::single = 1; my $fh = IO::Pipe->new(); - my @cmd = ( "$basedir/bin/uml2xmi", $input ); + my @cmd = ( $^X, "$basedir/bin/uml2xmi", $input ); { - local $" = ' '; +#~ local $" = ' '; + print STDERR "IO::Pipe ummi >> @cmd << \n"; $fh->reader(@cmd) || die("Cannot run '@cmd': $!"); } diff -ru UMMF-1.02/lib/UMMF/Import/XMI.pm UMMF-1.02-new5/lib/UMMF/Impo +rt/XMI.pm --- UMMF-1.02/lib/UMMF/Import/XMI.pm 2006-05-13 18:40:03.000000000 +-0700 +++ UMMF-1.02-new5/lib/UMMF/Import/XMI.pm 2011-07-29 04:47:29.96875 +0000 -0700 @@ -573,7 +573,23 @@ # Handle <XMI.field>DATA</XMI.field> if ( $name eq 'XMI.field' ) { - return $node->getData; +#~ http://www.perlmonks.org/?node_id=62809# XML::DOM::Parser + sub XML::DOM::Element::getData { + package XML::DOM::Element; + my( $node ) = @_; + my $data = ""; + for my $child($node->getChildNodes) { + if($child->getNodeType == TEXT_NODE) { + $data .= $child->getData; + } + } + return $data; + } + my $ret = eval { $node->getData }; +#~ warn $@ ? $@ : "$ret "; + $ret = $node->getNodeValue unless length $ret; +#~ warn " $node ", $node->getNodeType , " " unless length $ret; + return $ret; } if ( $name eq 'XMI.any' ) { return $node->getData; diff -ru UMMF-1.02/lib/UMMF/XForm/Merge.pm UMMF-1.02-new5/lib/UMMF/XFo +rm/Merge.pm --- UMMF-1.02/lib/UMMF/XForm/Merge.pm 2005-04-11 22:40:43.000000000 + -0700 +++ UMMF-1.02-new5/lib/UMMF/XForm/Merge.pm 2011-07-29 04:40:38.0156 +25000 -0700 @@ -121,7 +121,7 @@ sub merge_ModelElements_1 { my ($self, $model, $modelx, $ns, $nsx) = @_; - +warn join "\n", map { "[ $_ ] " } @_; for my $objx ( $nsx->ownedElement ) { my $name = $objx->name; my $obj = Namespace_ownedElement_name($ns, $name); diff -ru UMMF-1.02/lib/UMMF.pm UMMF-1.02-new5/lib/UMMF.pm --- UMMF-1.02/lib/UMMF.pm 2006-05-13 18:40:03.000000000 -0700 +++ UMMF-1.02-new5/lib/UMMF.pm 2011-07-29 04:40:38.015625000 -0700 @@ -373,6 +373,8 @@ Returns a list of directories to search for files of type C<$type>. =cut + +use File::ShareDir qw' dist_dir '; sub resource_path { my ($self, $type) = @_; @@ -400,6 +402,7 @@ # Default installation path. &module_dir . "/data", + dist_dir('UMMF', 'ummf'), # it works ), ); } diff -ru UMMF-1.02/Makefile.PL UMMF-1.02-new5/Makefile.PL --- UMMF-1.02/Makefile.PL 2004-08-01 14:19:09.000000000 -0700 +++ UMMF-1.02-new5/Makefile.PL 2011-07-29 04:40:38.015625000 -0700 @@ -2,6 +2,9 @@ use 5.006001; use ExtUtils::MakeMaker; +use File::ShareDir::Install; +install_share 'dist', 'data'; # install data into + # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( @@ -47,3 +50,8 @@ (ABSTRACT_FROM => 'lib/UMMF.pm', # retrieve abstract from modu +le AUTHOR => 'Kurt Stephens <kstephens@users.sourceforge. +net>') : ()), ); + + package MY; + use File::ShareDir::Install qw(postamble); # it works + +

Replies are listed 'Best First'.
Re^6: UML to Perl
by Anonymous Monk on Jul 29, 2011 at 13:06 UTC
    cd UMMF-1.02\example\ex2 ummf -e Java -o gen/java OddNames.zuml ummf -e Perl -o gen/perl OddNames.zuml perl -Igen/perl -MEx2::Class_With_Spaces -MEx2::Class_with_dashes -e 1 tree -f gen
    gen |-- gen/java | |-- gen/java/UML | | |-- gen/java/UML/__Factory.java | | `-- gen/java/UML/__Model.java | `-- gen/java/ex2 | |-- gen/java/ex2/Another_Class_with_spaces.java | |-- gen/java/ex2/Class_With_Spaces.java | |-- gen/java/ex2/Class_with_dashes.java | |-- gen/java/ex2/IAnother_Class_with_spaces.java | |-- gen/java/ex2/IClass_With_Spaces.java | `-- gen/java/ex2/IClass_with_dashes.java `-- gen/perl |-- gen/perl/Ex2 | |-- gen/perl/Ex2/Another_Class_with_spaces.pm | |-- gen/perl/Ex2/Class_With_Spaces.pm | `-- gen/perl/Ex2/Class_with_dashes.pm |-- gen/perl/UML | `-- gen/perl/UML/__ObjectBase.pm |-- gen/perl/UML.pm `-- gen/perl/UML.pm.Model.xmi
      Hi,

      Could you pls explain a bit about what "diff" exactly are we "patching" in in the sample patch run that you showed above?

      Am just trying to understand the logic here. I am getting a "template not found" error; but the sample patch run u showed me seems to be taking a diff between some old version of UMMF files2dirs file and a newer version of the same.

      Can you please explain a bit as to how this explanation would solve my problem?

      I was thinking on these lines - to me the error looks like a template file that's used to generate code is missing here for some reason. So, if we can get hold of that template file, then my problem should be resolved. Am I thinking right?

      Please advise.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://917460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-03-28 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found