Discussion:
[devinfo] Template passing MORE_DATA
John Crisp
2018-07-17 15:24:01 UTC
Permalink
Well, I read the wiki, looked at a load of other files in he
/etc/e-smith hierarchy, and just cannot get this to work.

I have a file to process a set of fragments for multiple domains.

I want the calling file to pass the Domain to the fragment, per domain,
to create one conf file per domain.

Here's the calling file:

require esmith::DomainsDB;
my %Domains = esmith::DomainsDB->as_hash;
for (keys %Domains) {
my $domain = $_;

esmith::templates::processTemplate(
        {
            MORE_DATA => { THIS_DOMAIN => $domain },
            TEMPLATE_PATH =>
'/etc/e-smith/web/panels/manager/cgi-bin/.awstats/awstats.conf',
            OUTPUT_FILENAME =>
"/etc/e-smith/web/panels/manager/cgi-bin/.awstats/awstats.$domain.conf",
        }
    );



In the template fragment I have this:

my $domain = $THIS_DOMAIN;
$OUT = "SiteDomain=\"www." . $domain . "\"\n";

I also tried

$OUT = "SiteDomain=\"www." . $THIS_DOMAIN . "\"\n";

No matter what I do I get

Variable "$THIS_DOMAIN" is not imported

Program fragment delivered error <<Global symbol "$THIS_DOMAIN" requires
explicit package name

Frustratingly via my IDE I can see the THIS_DOMAIN gets set correctly ,
and puts that into @tmpl_vars[3] -> THIS_DOMAIN

But I get lost after that :-(

Anyone give me a clue what on earth I am doing wrong here? I know it is
stupidly simple,... but.....

B. Rgds
John
_______________________________________________
Server Development Discussion
To unsubscribe, e-mail devinfo-***@lists.contribs.org
Searchable archive at https://lists.contribs.o
John Crisp
2018-07-17 16:07:03 UTC
Permalink
It's not immediately obvious to me what's going on.
Me neither :-(
'use diagnostics;'
to your script and see if it tells you more.
Tried that - nothing I can see.
Failing that, email me a bunch of files so that I can replicate your
problem.
OK - I'll bundle a few up for you

Thanks

_______________________________________________
Server Development Discussion
To unsubscribe, e-mail devinfo-***@lists.contribs.org
Searchable archive at https://lists.contribs.org/mailman/public/devinfo/
John Crisp
2018-07-17 16:37:30 UTC
Permalink
Post by John Crisp
require esmith::DomainsDB;
my %Domains = esmith::DomainsDB->as_hash;
for (keys %Domains) {
my $domain = $_;
Not necessarily responsible for your problem, but I would avoid the use of
the global variable $_ here (even though it is localized for the 'for'
loop).
OK - I inherited it - so it isn't all my fault ;-)

This was old code that I was trying to update a bit, and fix some issues
at the same time.
...
foreach my $domain (keys %Domains)
...
OK
And why are you using 'as_hash' here? Why not?
...
foreach my $domain (esmith::DomainsDB->open->get_all)
{
# use $domain->key
...
As above - I inherited and know no better....



NB - I just noticed this from your use diagnostics which I had missed.

Variable "$THIS_DOMAIN" is not imported at
/etc/e-smith/templates-custom//etc/e-smith/web/panels/manager/cgi-bin/.awstats/awstats.conf/06domain line 30 (#1)
(F) While "use strict" in effect, you referred to a global variable that
you apparently thought was imported from another module, because
something else of the same name (usually a subroutine) is exported by
that module. It usually means you put the wrong funny character on the
front of your variable.
_______________________________________________
Server Development Discussion
To unsubscribe, e-mail devinfo-***@lists.contribs.org
Searchable archive at https://lists.contribs.org/mailman/public/devinfo/
John Crisp
2018-07-17 21:33:59 UTC
Permalink
Post by John Crisp
This was old code that I was trying to update a bit, and fix some issues
at the same time.
Maybe it would be a good idea to rewrite from scratch.
Ha - like I have the skills :-)

I agree it would be good, but there is a lot of trick stuff in there
(for me at least). Taken me days to get as far as I have........

I have been trying to break some of it out, update some stuff, remove
some cruft that isn't needed (IE 6 out there anyone?) etc

If I can get the basics working the way I think it should then it can be
progressed if needs be.

Small steps.....
_______________________________________________
Server Development Discussion
To unsubscribe, e-mail devinfo-***@lists.contribs.org
Searchable archive at https://lists.contribs.org/mailman/public/devinfo/
John Crisp
2018-07-17 21:58:03 UTC
Permalink
Post by John Crisp
my $domain = $THIS_DOMAIN;
$OUT = "SiteDomain=\"www." . $domain . "\"\n";
use strict;
Remove it from 06domain and 07datadir and you won't see those errors any
longer.
OK
I don't think you will get the functionality you need until you also
OUTPUT_TYPE => 'string',
from conf-awstats.
That was another attempt after the earlier failures.

Yayyyyyy - Got it... finally.

Remove strict. Then:

my $domain = $THIS_DOMAIN;
$OUT = "SiteDomain=\"www.$domain\"\n";

SiteDomain="www.reetspetit.net"


my $domain = $THIS_DOMAIN;
$OUT = "DirData=\"/home/e-smith/files/users/admin/home/awstats/$domain\"\n";


DirData="/home/e-smith/files/users/admin/home/awstats/reetspetit.net"

Sorted !
$configDB->get_prop( "AWStats", "UseFramesWhenCGI" )
$AWStats{UseFramesWhenCGI}
use esmith::ConfigDB;
my $configDB = esmith::ConfigDB->open or die("can't open Config DB");
my $OUT;
in multiple places - and your code will run more quickly.
OK. I think I had done that just so I knew where the hell I was when I
was building the templates. I can do that now thanks.

Thank you VERY MUCH for your help. I was pulling my hair out !

B. Rgds
John
_______________________________________________
Server Development Discussion
To unsubscribe, e-mail devinfo-***@lists.contribs.org
Searchable archive at https://lists.contribs.org/mailman/public/devinfo/
Loading...