Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
global perl module
gschwa
I am trying to create a Perl module for some global functions to be used across different TPL files. As a test I am trying to make the following function global:
sub WriteResource {
my $resourceName = shift;
return "<resource name='" . $resourceName . "'><!["."CDATA[". iwpt_dcr_value('dcr.pagedef.resources.'.$resourceName) . "]"."]></resource>";
}
I created a mymodule.pm but of course the module does not know how to deal with "iwpt_dcr_value" function. How do I make this work? I would like the external module to be able to access the DCR.
Find more posts tagged with
Comments
Adam Stoller
Try adding:
use TeamSite:
T::iw_perl;
to your module and see if that works.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
gschwa
That didn't work
Any other ideas? Does anyone have any sample code?
Adam Stoller
Perhaps something like this in your module:
sub WriteResource {
my $resourceName = shift;
return qq("<resource name='$resourceName'><!["."CDATA[". iwpt_dcr_value("dcr.pagedef.resources.$resourceName") . "]"."]></resource>");
}
with something like this in the code that uses your module:
eval(WriteResource($resourceName));
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
gschwa
It still chokes on the iwpt_dcr_value function. Do you know a way to pass the dcr as a variable to the function? And then use some of the other TeamSite functions to access the fields?
Adam Stoller
My quoting may have been wrong in the previous example - I didn't try anything out.
The objective is to make the string that you pass back contain the iwpt_dcr_value() function [not it's result] and to then evaluate that string in the context of an <iw_perl> section of your PT where it should work -- note - it might be something like: my $x = eval(....); or iwpt_output(eval(....));
If the code is still breaking within the module at the point where iwpt_dcr_value() exists - than the quoting is wrong because you want to avoid having that function call evaluated within the module code itself.
You'll probably have to play with it a bit to get it to work - but I'm pretty sure that it's generally a workable direction to head in.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
gschwa
I tried what you recommended but all it is outputting is iwpt_dcr_value(...) in the output! It is not evaluating the expression. This is very frustrating. I would expect that this is done often to avoid duplicate code in multiple TPL files. But I guess not.
Adam Stoller
Try switching the logic around:
sub WriteResource {
my($resourceName, $val) =
@_
;
return qq("<resource name='$resourceName'><!["."CDATA[$val]"."]></resource>");
}
with something like this in the code that uses your module:
iwpt_output(WriteResource($resourceName, iwpt_dcr_value("dcr.pagedef.resources.$resourceName"));
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Migrateduser
I always enjoy reading ghoti's posts because I often learn something, but I had to put in my $0.02 in this one... the statement is missing a ")".
Anxious to find out how this particular issue will be solved,
Dave
Current Environment(s):
(1) TS 6.5 on W2K3
(2) TS 6.1 SP1 on W2K3
By the way, I miss Unix terribly.
gschwa
A good suggestion but that will only work in this simple case. I have some complex DCT structures that I want to write out in a consistent way across multiple TPLs. Another option I think is to open the DCR in the module and pull out the values.
Do you know how to get the DCR XML or the path of the DCR being processed from within the TPL file?
Adam Stoller
Look at TeamSite::XMLnode for parsing.
For getting the dcr - you can pass that into the subroutine or perhaps register it in some module-scoped variable.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com