From: <et...@co...> - 2019-12-19 01:16:12
|
Hello! I am new to Mason and have a little problem in having the same application (but with different configuration) multiple times on a server in different paths. Think the problem is because of the global scope of packages. I have the configuation data in a package - lets say MyConfig. e.g. package MyConfig; sub getColor { return "red"; } 1; I load it in the autohandler and via MyConfig::getColor () it is available in all parts of the application. Lets say I wanna have the same application a 2nd time on the same server but with a different color. So both applications would have the same files but MyConfig.pm differs. That does not work. The color get mixed up unless I do not have unique names for the config-package (e.g. MyConfig1 in the 1st application and MyConfig2 in the 2nd) again. Thats not great because I also need to change every appearence of MyConfig::getColor () to the new name. Is there a way I can bring such static configuration data in the application in a more elegant way? Thanks for help! Chris |
From: Han Do J. <ang...@gm...> - 2019-12-19 01:42:17
|
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 et...@co... <et...@co...> wrote: > Hello! > > I am new to Mason and have a little problem in having the same > application (but with different configuration) multiple times on a > server in different paths. > Think the problem is because of the global scope of packages. > > I have the configuation data in a package - lets say MyConfig. > > e.g. > package MyConfig; > > sub getColor > { > return "red"; > } > > 1; > > I load it in the autohandler and via MyConfig::getColor () it is > available in all parts of the application. > > Lets say I wanna have the same application a 2nd time on the same server > but with a different color. > So both applications would have the same files but MyConfig.pm differs. > > That does not work. The color get mixed up unless I do not have unique > names for the config-package (e.g. MyConfig1 in the 1st application and > MyConfig2 in the 2nd) again. > Thats not great because I also need to change every appearence of > MyConfig::getColor () to the new name. > > Is there a way I can bring such static configuration data in the > application in a more elegant way? > > Thanks for help! > Chris > > > _______________________________________________ > Mason-users mailing list > Mas...@li... > https://lists.sourceforge.net/lists/listinfo/mason-users > |
From: <et...@co...> - 2019-12-19 08:03:30
|
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 { 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 { 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 et...@co... > <mailto:et...@co...> <et...@co... > <mailto:et...@co...>> wrote: > > Hello! > > I am new to Mason and have a little problem in having the same > application (but with different configuration) multiple times on a > server in different paths. > Think the problem is because of the global scope of packages. > > I have the configuation data in a package - lets say MyConfig. > > e.g. > package MyConfig; > > sub getColor > { > return "red"; > } > > 1; > > I load it in the autohandler and via MyConfig::getColor () it is > available in all parts of the application. > > Lets say I wanna have the same application a 2nd time on the same > server > but with a different color. > So both applications would have the same files but MyConfig.pm > differs. > > That does not work. The color get mixed up unless I do not have > unique > names for the config-package (e.g. MyConfig1 in the 1st > application and > MyConfig2 in the 2nd) again. > Thats not great because I also need to change every appearence of > MyConfig::getColor () to the new name. > > Is there a way I can bring such static configuration data in the > application in a more elegant way? > > Thanks for help! > Chris > > > _______________________________________________ > Mason-users mailing list > Mas...@li... > <mailto:Mas...@li...> > https://lists.sourceforge.net/lists/listinfo/mason-users > |
From: Seb <se...@h-...> - 2019-12-19 09:20:52
|
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 our %config = ( 'getColor' => 'red', ); 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 getColor" according to the DOCUMENT_ROOT, eg return ($ENV{'DOCUMENT_ROOT'} eq "···") ? "red" : ($ENV{'DOCUMENT_ROOT'} eq "···") ? "blue" : "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ébastien. et...@co... (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 > { > 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 > { > 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 et...@co... >> <mailto:et...@co...> <et...@co... >> <mailto:et...@co...>> wrote: >> >> Hello! >> >> I am new to Mason and have a little problem in having the same >> application (but with different configuration) multiple times on a >> server in different paths. >> Think the problem is because of the global scope of packages. >> >> I have the configuation data in a package - lets say MyConfig. >> >> e.g. >> package MyConfig; >> >> sub getColor >> { >> return "red"; >> } >> >> 1; >> >> I load it in the autohandler and via MyConfig::getColor () it is >> available in all parts of the application. >> >> Lets say I wanna have the same application a 2nd time on the same >> server >> but with a different color. >> So both applications would have the same files but MyConfig.pm >> differs. >> >> That does not work. The color get mixed up unless I do not have >> unique >> names for the config-package (e.g. MyConfig1 in the 1st >> application and >> MyConfig2 in the 2nd) again. >> Thats not great because I also need to change every appearence of >> MyConfig::getColor () to the new name. >> >> Is there a way I can bring such static configuration data in the >> application in a more elegant way? >> >> Thanks for help! >> Chris >> >> >> _______________________________________________ >> Mason-users mailing list >> Mas...@li... >> <mailto:Mas...@li...> >> https://lists.sourceforge.net/lists/listinfo/mason-users >> > > |
From: <et...@co...> - 2019-12-19 11:05:29
|
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 > our %config = ( > 'getColor' => 'red', > ); > 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 getColor" according to the DOCUMENT_ROOT, eg > return ($ENV{'DOCUMENT_ROOT'} eq "···") ? "red" > : ($ENV{'DOCUMENT_ROOT'} eq "···") ? "blue" > : "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ébastien. > > et...@co... (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 >> { >> 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 >> { >> 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 et...@co... >>> <mailto:et...@co...> <et...@co... >>> <mailto:et...@co...>> wrote: >>> >>> Hello! >>> >>> I am new to Mason and have a little problem in having the same >>> application (but with different configuration) multiple times on a >>> server in different paths. >>> Think the problem is because of the global scope of packages. >>> >>> I have the configuation data in a package - lets say MyConfig. >>> >>> e.g. >>> package MyConfig; >>> >>> sub getColor >>> { >>> return "red"; >>> } >>> >>> 1; >>> >>> I load it in the autohandler and via MyConfig::getColor () it is >>> available in all parts of the application. >>> >>> Lets say I wanna have the same application a 2nd time on the same >>> server >>> but with a different color. >>> So both applications would have the same files but MyConfig.pm >>> differs. >>> >>> That does not work. The color get mixed up unless I do not have >>> unique >>> names for the config-package (e.g. MyConfig1 in the 1st >>> application and >>> MyConfig2 in the 2nd) again. >>> Thats not great because I also need to change every appearence of >>> MyConfig::getColor () to the new name. >>> >>> Is there a way I can bring such static configuration data in the >>> application in a more elegant way? >>> >>> Thanks for help! >>> Chris >>> >>> >>> _______________________________________________ >>> Mason-users mailing list >>> Mas...@li... >>> <mailto:Mas...@li...> >>> https://lists.sourceforge.net/lists/listinfo/mason-users >>> >> >> |
From: Seb <se...@h-...> - 2019-12-19 11:30:43
|
Hi, > As far I see %config from your 1st sample is not available outside the > autohandler. Otherwise I would do it that way. Ah yes, sorry, I forgot that I had made %config a global variable in Apache: # grep config <site>.conf PerlAddVar MasonAllowGlobals %config Best regards, Sébastien. > 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 >> our %config = ( >> 'getColor' => 'red', >> ); >> 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 getColor" according to the DOCUMENT_ROOT, eg >> return ($ENV{'DOCUMENT_ROOT'} eq "···") ? "red" >> : ($ENV{'DOCUMENT_ROOT'} eq "···") ? "blue" >> : "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ébastien. >> >> et...@co... (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 >>> { >>> 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 >>> { >>> 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 et...@co... >>>> <mailto:et...@co...> <et...@co... >>>> <mailto:et...@co...>> wrote: >>>> >>>> Hello! >>>> >>>> I am new to Mason and have a little problem in having the same >>>> application (but with different configuration) multiple times on a >>>> server in different paths. >>>> Think the problem is because of the global scope of packages. >>>> >>>> I have the configuation data in a package - lets say MyConfig. >>>> >>>> e.g. >>>> package MyConfig; >>>> >>>> sub getColor >>>> { >>>> return "red"; >>>> } >>>> >>>> 1; >>>> >>>> I load it in the autohandler and via MyConfig::getColor () it is >>>> available in all parts of the application. >>>> >>>> Lets say I wanna have the same application a 2nd time on the same >>>> server >>>> but with a different color. >>>> So both applications would have the same files but MyConfig.pm >>>> differs. >>>> >>>> That does not work. The color get mixed up unless I do not have >>>> unique >>>> names for the config-package (e.g. MyConfig1 in the 1st >>>> application and >>>> MyConfig2 in the 2nd) again. >>>> Thats not great because I also need to change every appearence of >>>> MyConfig::getColor () to the new name. >>>> >>>> Is there a way I can bring such static configuration data in the >>>> application in a more elegant way? >>>> >>>> Thanks for help! >>>> Chris >>>> >>>> >>>> _______________________________________________ >>>> Mason-users mailing list >>>> Mas...@li... >>>> <mailto:Mas...@li...> >>>> https://lists.sourceforge.net/lists/listinfo/mason-users >>>> >>> >>> > |
From: Guido B. <gd...@le...> - 2019-12-19 11:32:08
|
----- Il 19-dic-19, alle 12:05, et...@co... ha scritto: > 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 > You must declare global variables. Please look at https://metacpan.org/pod/HTML::Mason::Compiler allow_globals parameter bye gdo |