On Dec 5, 2007 2:34 PM, Jonathan Swartz <[EMAIL PROTECTED]> wrote:
> You can set up actual globals:
>
> http://www.masonhq.com/docs/manual/Admin.html#global_variables
>
> Though I prefer to prefix all globals with an app prefix for
> readability, e.g.
>
> $MyApp::msg
>
>
> On Dec 5, 2007, at 11:30 AM, Anthony Ettinger wrote:
>
> > I have an object (contains UI messaging interface) that I want to
> > persist throughout all the mason parts/includes in a request.
> >
> > How should I do this?
> >
> > autohandler?:
> > my $msg = new UI::Msg;
> >
> > so from within any part, file, or page now has access to $msg object:
> >
> > An example below:
> >
> > /parts/foo
> > $msg->err("There was an error with FOO");
> >
> > /parts/bar
> > $msg->ok("Bar processed correctly!");
> >
> > /autohandler:
> > print $msg->errors();
> >
> >
> > Similar to the global $m (mason object)...I do not want to have to
> > pass $msg object explicitly to all my files.
> >
> > --
> > Anthony Ettinger
> > 408-656-2473
> > http://anthony.ettinger.name
> >
> > var (bonita, farley) = new Dog;
> > farley.barks("very loud");
> > bonita.barks("at strangers");
> >
> > ----------------------------------------------------------------------
>


One problem with globals that arose, was that it is shared among the
requests for a given apache process.

In effect, I just want this thing to die off at the end of each http
request, and not shared between other users of the application. This
works fine if I create the instance in an autohandler's <init> block,
but I also wanted the backend database calls (perl modules) to be able
to throw messages to it as well, where the data will eventually be
validated (MVC methodology).

Case in point: filling out a form with your phone number, and someone
else fills out the same form at the same time with an invalid email,
if the messages went to the wrong user, or persisted after the form
submission it would not make any sense.





-- 
Anthony Ettinger
408-656-2473
http://anthony.ettinger.name

var (bonita, farley) = new Dog;
farley.barks("very loud");
bonita.barks("at strangers");

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to