XyPerl and CSS and the use of Modules.

I have a puzzle ... I see from the documentation that you can use this syntax in the CSS:
-xpp-perl(myfunc);
or
-xpp-perl-mfrag(myfunc);

However I wanted to call a function (myfunc2) that is in a module file in my JOB folder (say, mymodule.pm)
and I have tried this in the CSS file:
-xpp-perl-mfrag(mymodule::myfunc2);
Now that seems to start off OK as without the "mymodule::" part I do get an error message on compose saying that myfunc2 subroutine cannot be found.
But the mymodule::myfunc2 subroutine does not seem to be actually actioned when I run compose.

So, I'm wondering if the -xpp-perl and -xpp-perl-mfrag fully allow a first argument that includes a module name?


As a test of the myfunc2  subroutine I
- set up the CSS to call a simple subroutine in my main .pl program
- that simple subroutine in the main .pl program just called the module-based function I was really trying to access
i.e.
mymodule::myfunc2();

and that did seem to work OK.


Paul

  • Paul,

    Do not forget that your XyPerl functions already live in a package that has the style name. In order to make your live easier compose will add that package name to your function. So if you have a style called 'normal' and you want to use the function 'myfunction()', compose will actually call out function 'normal::myfunction()' for you. I guess you now understand why calling mymodule::myfunct2() does not work...

    If you want to use a module in which you gather all of your functions that you want to share in between different styles, here is what I do:
    Lets say the style you are using is called 'normal' and your module is called 'shared.pm' and you want to share the function called 'sharedFunction()'

    So in the 'normal.pl' file you do:

        package normal;
        use strict;
        use warnings;
        use 5.028;
        
        use Shared;
    

    and then in the 'Shared.pm' you do:

        package Shared;
    
        use strict;
        use warnings;
        use 5.028;
        
        use Exporter qw(import);
        our @ISA = qw(Exporter);
        our @EXPORT = qw(	sharedFuntion);
        
        sub sharedFunction {
        ...
        }
        
        1;
    

    So you export that function sharedFunction from your module 'Shared' package and that will get imported into namespace of the package 'normnal' when you do the 'use Shared;'. From then on you can call the sharedFunction() in the normal way as compose will call it out as 'normal::sharedFunction()'. You can add as many function to the @EXPORT array as you wish. You can decide like this which functions you want to make public and which functions you want to keep private to the Shared package.

  • Fantastic - thanks very much Bart for your clear answer and example - much appreciated.