Re: Having configuration-data in a package with multiple instances of the same app

"[email protected]" <[email protected]> Thu, 19 Dec 2019 12:05:18 +0100
Newsgroups gmane.comp.web.mason.user
Message-ID <[email protected]>
Hello!

As far I see %config from your 1st sample is not available outside the =

autohandler.

Otherwise I would do it that way.

Best regards,
Christoph

On 19.12.19 10:02, Seb wrote:
>
> Hi,
>
>
> Using a library is but one a several ways to make an information =

> available to all parts of your website. For the need you describe, =

> perhaps you would get an equivalent functionality by setting
> =A0=A0=A0 our %config =3D (
> =A0=A0=A0=A0=A0=A0=A0 'getColor' =3D> 'red',
> =A0=A0=A0 );
> in the autohandler. Then any component could use $config{'getColor'}.
>
> If you really want, or need, a library, I suggest you make subcases in =

> "sub=A0getColor" according to the DOCUMENT_ROOT, eg
> =A0=A0=A0 return ($ENV{'DOCUMENT_ROOT'} eq "=B7=B7=B7") ? "red"
> =A0=A0=A0=A0=A0=A0=A0=A0 : ($ENV{'DOCUMENT_ROOT'} eq "=B7=B7=B7") ? "blue"
> =A0=A0=A0=A0=A0=A0=A0=A0 : "black";
> NB: I haven't tested this; perhaps you would need to call your =

> function as MyConfig::getColor($ENV{'DOCUMENT_ROOT'}) instead.
>
>
> Kind regards,
> S=E9bastien.
>
> [email protected] (Thu, 19 Dec 2019):
>
>> Hello!
>>
>> Thanks for support.
>>
>> Here is the essential of my sample for app1 and app2. I try to put a =

>> config-item (the color) into a package. The color should be different =

>> between app1 and app2.
>> The config-package has in every app the same name MyConfig (that may =

>> be the problem). I can resolve the problem if I make MyConfig1 for =

>> app1 and MyConfig2 for app2.
>> But lets think I have not 2 apps but 10. I would need to change every =

>> apperance of MyConfig::getColor in the code.
>>
>> Cheers
>> Chris
>>
>>
>> --app1/autohandler--
>> % $m->call_next ();
>> <%init>
>> use strict;
>> use warnings;
>> use lib "/var/www/html/app1";
>> use MyConfig;
>> </%init>
>>
>>
>> --/app1/MyConfig.pm--
>> package MyConfig;
>> sub getColor
>> {
>> =A0=A0=A0=A0 return "red";
>> }
>> 1;
>>
>>
>> --app2/index.mas--
>> <% MyConfig::getColor () %>
>>
>>
>> --app2/autohandler--
>> % $m->call_next ();
>> <%init>
>> use strict;
>> use warnings;
>> use lib "/var/www/html/app2";
>> use MyConfig;
>> </%init>
>>
>>
>> --/app12MyConfig.pm--
>> package MyConfig;
>> sub getColor
>> {
>> =A0=A0=A0=A0 return "blue";
>> }
>> 1;
>>
>> --app2/index.mas--
>> <% MyConfig::getColor () %>
>>
>>
>>
>>
>>
>> On 19.12.19 02:41, Han Do Jin wrote:
>>> Can you show us your autohandler? I think maybe you should be using =

>>> <%attr> to affect a shared template rather than put configs into a =

>>> shared library. I'm guessing when you say you want same application =

>>> 2nd time on same server that they are both running in the same =

>>> apache instance? I run multiple sites (virtualhosts) on the same =

>>> apache instance and use a few techniques for altering the =

>>> core/shared master template as well as which database to connect to. =

>>> Let's see what you are trying to accomplish and I can try and offer =

>>> you some more concrete examples.
>>>
>>> Chris
>>>
>>>
>>> On Wed, Dec 18, 2019 at 5:16 PM [email protected] =

>>> <mailto:[email protected]> <[email protected] =

>>> <mailto:[email protected]>> wrote:
>>>
>>> =A0=A0=A0 Hello!
>>>
>>> =A0=A0=A0 I am new to Mason and have a little problem in having the same
>>> =A0=A0=A0 application (but with different configuration) multiple times=
 on a
>>> =A0=A0=A0 server in different paths.
>>> =A0=A0=A0 Think the problem is because of the global scope of packages.
>>>
>>> =A0=A0=A0 I have the configuation data in a package - lets say MyConfig.
>>>
>>> =A0=A0=A0 e.g.
>>> =A0=A0=A0 package MyConfig;
>>>
>>> =A0=A0=A0 sub getColor
>>> =A0=A0=A0 {
>>> =A0=A0=A0 =A0=A0=A0=A0 return "red";
>>> =A0=A0=A0 }
>>>
>>> =A0=A0=A0 1;
>>>
>>> =A0=A0=A0 I load it in the autohandler and via MyConfig::getColor () it=
 is
>>> =A0=A0=A0 available in all parts of the application.
>>>
>>> =A0=A0=A0 Lets say I wanna have the same application a 2nd time on the =
same
>>> =A0=A0=A0 server
>>> =A0=A0=A0 but with a different color.
>>> =A0=A0=A0 So both applications would have the same files but MyConfig.pm
>>> =A0=A0=A0 differs.
>>>
>>> =A0=A0=A0 That does not work. The color get mixed up unless I do not ha=
ve
>>> =A0=A0=A0 unique
>>> =A0=A0=A0 names for the config-package (e.g. MyConfig1 in the 1st
>>> =A0=A0=A0 application and
>>> =A0=A0=A0 MyConfig2 in the 2nd) again.
>>> =A0=A0=A0 Thats not great because I also need to change every appearenc=
e of
>>> =A0=A0=A0 MyConfig::getColor () to the new name.
>>>
>>> =A0=A0=A0 Is there a way I can bring such static configuration data in =
the
>>> =A0=A0=A0 application in a more elegant way?
>>>
>>> =A0=A0=A0 Thanks for help!
>>> =A0=A0=A0 Chris
>>>
>>>
>>> =A0=A0=A0 _______________________________________________
>>> =A0=A0=A0 Mason-users mailing list
>>> =A0=A0=A0 [email protected]
>>> =A0=A0=A0 <mailto:[email protected]>
>>> =A0=A0=A0 https://lists.sourceforge.net/lists/listinfo/mason-users
>>>
>>
>>