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)
including perl module
cheeku
Hi All,
I want to include a perl module(.pm file) in my code.
The normal way to include module in a tpl file is
use lib 'Y:/default/main/tstbranch/WORKAREA/global';
use Groupconfig;
Now here 'Y:/default/main/tstbranch/WORKAREA/global' is the path in teamsite where Groupconfig.pm is laying.Also 'global' is the workarea in my tstbranch branch.
i have a lot of sites in my teamsite with the same structure only the branch name is different for all the sites.so for every branch i do not want to change the lib path for each of the site
So i want to dynamically include the branch name 'tstbranch' in this use lib statement.i tried to give the name which i picked up in tpl file using iwpt_get_ofile_name('dirname'). but it didnt work.
So in the above statements i want to dynamically pick the branch name 'tstbranch'. Can anybody give me pointers on this?
Thanx in advance
Find more posts tagged with
Comments
Adam Stoller
First of all, it might be better to place the module in
iwhome
/iw-perl/site/lib/
orgname
/
and package and refer to the module as
orgname
::Groupconfig
- if you want to version the module, do so in an
admin
branch that deploys to the local disk.
However, given your current implementation - you need to use a
BEGIN
block, like so (untested, but should work I believe):
...
<iw_perl>
my $branch;
BEGIN{
($branch = iwpt_get_ofile_name('dirname')) =~ tr|\\|/|;
$branch =~ s|(/WORKAREA/[^/]+)/.*|$1|;
# Alt: $branch =~ s|/WORKAREA/.*|/STAGING|;
use lib "$branch/global";
use Groupconfig;
};
...
</iw_perl>
...
(it's either that, or move the two
use
lines after the BEGIN block - but I think they go inside).
Hope that helps.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
cheeku
Hi,
Thanx for the response on this. but in BEGIN block, "iwpt_get_ofile_name('dirname')" does not seem to work.
I tried using this code but in begin block its not picking up the path from iwpt_get_ofile_name('dirname').
Any alternative solution for that?
Adam Stoller
You'll have to play with the code a bit - perhaps you need an additional 'use' statement before or within the BEGIN block.
I don't have your situation, so I don't have a reason to try and figure this out right now (as opposed to doing the work I'm actually getting paid for) so I suggest you just play around with it a bit to see if you can figure it out yourself.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
alanhill
Cheeku,
Not sure how much help it is but I have some generic code that I use in multiple templates. The two lines of code I use are:
use lib 'y:\\default\\main\\wwwsites\\...\\tpl\\';
use commonPresentationRoutines;
You'll need to put your correct path in the 'use lib' statement of course, but for a PM that I have called 'commonPresentationRoutines.pm' this works a treat.
Cheers
Teamsite Template Developer
Adam Stoller
The idea is to *avoid* hard-coding a lib path into the code
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com