gtwebb
gtwebb

Reputation: 3011

How to manage functions that are in multiple modules when one is unknown

I'm attempting to edit a script in Lava (Perl language that has been extended for use in the mining software Vulcan).

I've run into an issue with modules and as I'm not used to Perl I haven't been able to solve it completely.

A snippet of the code is below

The module that is causing issues is "Macro".

use Lava;
use warnings;
use strict;
use vulcan;
use utf8;
use Macro 'RunMenu';
use File::Basename;

my $tri = 'C:\\_PROJECTS\\1404134_abc\\VULCAN\\faults.tri\\retriangulated\\gbc_ne1e_1606.00t';
my $tr = new Triangulation($tri);

#Runs fine
RunMenu("TRI_UTE_LOAD:$tri","abort",
      "FINISH") || die "Macro mismatch.\n";

#Does not run fine
RunMenu("TRI_EDIT_INTERP","abort",
      sub { Triangulation("$basedir\\$tri"); },

      sub { PanelResults("Select interpolation option",
                "line" => "",
                "Maximum triangle area  " => "$maxTriArea",
                "Maximum boundary length" => "100.0",
                "button_pressed" => "ok",
                "Interpolate midpoints" => "1",
                "Interpolate centroids" => "0",
                "Honour breaklines" => "1"
                   ); },
      "FINISH") || die "Macro mismatch.\n";

If I omit use Macro; this line my $tr = new Triangulation($tri); runs fine but then I can't use the RunMenu command.

If I include use Macro; I get Bareword found where operator expected at C:\_PROJECTS\1404134_abc\VULCAN\new.lava line 12, near "new Triangulation" (Do you need to predeclare new?)

The closest I've got is use Macro 'RunMenu'; but then I get Undefined subroutine &main::Triangulation called at C:\_PROJECTS\1404134_abc\VULCAN\test4.lava line 45.

What I believe is happening is Macro contains a function triangulation which is overwriting one in some other module (Don't know which module it is in or how to find out, I tried commenting out the other ones I load and it ran fine without all of them).

Any suggestions on how to use the two different triangulation functions when I don't know where one comes from? Or if anyone can suggest any other fixes it would be much appreciated.

The code is being run through Vulcan so I'm not sure which Perl debugging tools I can use.

Edit:

I've copied the help file below if your interested Help file

The most useful part was here

Triangulation Class

The Triangulation object provides an interface to the Envisage triangulation structures. The point and triangle data may be accessed through the member functions.

Each triangle consists of 3 vertex indices. These are indices into the point array, which holds a 3D location for each point. The triangles are formed by using the three sets of 3D points as vertices.

Methods: $triangulation = new Triangulation($name)

$triangulation : Returned triangulation object.
$name          : Optional triangulation name.

The constructor returns a new triangulation object. If a name is provided then the triangulation of the given name is loaded.

$result = is_valid

$result : Whether a triangulation has been successfully loaded or set.

$points = points

$points : The number of points in the triangulation

$triangles = triangles

$triangles : Number of triangles in the object

Upvotes: 2

Views: 182

Answers (1)

choroba
choroba

Reputation: 241918

It seems Triangulation is a class and function name at the same time. Perl doesn't know which one you want to use, but you can help it by using parentheses after function calls, you should also avoid "indirect object" syntax for methods, and possibly quote the class names or append :: to them:

my $tr = 'Triangulation'->new($tri);
# or
my $tr = Triangulation::->new($tri);

avoid:

my $tr = new Triangulation($tri);
Triangulation "$basedir\\$tri"; 

Upvotes: 7

Related Questions