Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

best practice for a protocol mechanism?

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


blacky6767 at gmx

Sep 8, 2009, 1:32 AM

Post #1 of 8 (1699 views)
Permalink
best practice for a protocol mechanism?

Hi,

I currently have an Catalyst application with several controllers and even more actions. Some of those actions require that I call my protocol action that - surprise, surprise - does some protocol work. This action is located in the Root controller. Right now I accomplish this with code snippets like this:

package MyApp::Controller::Foo
...
sub some_action :Local {
...
$c->forward("MyApp::Controller::Root","myProtocolAction",["some message that should be protocolled"]);
...
}

Is there some neater way to do this? (I started reading into the "Chains" topic but do not know if this protocolling mechanismn would be the right use case for chaining.)

Any ideas?

Thanks.

Jens


--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


zzbbyy at gmail

Sep 9, 2009, 1:15 PM

Post #2 of 8 (1599 views)
Permalink
Re: best practice for a protocol mechanism? [In reply to]

On Tue, Sep 8, 2009 at 10:32 AM, Jens Schwarz<blacky6767 [at] gmx> wrote:
> Hi,
>
> I currently have an Catalyst application with several controllers and even more actions. Some of those actions require that I call my protocol action that - surprise, surprise - does some protocol work. This action is located in the Root controller. Right now I accomplish this with code snippets like this:
>
> package MyApp::Controller::Foo
> ...
> sub some_action :Local {
> ...
> $c->forward("MyApp::Controller::Root","myProtocolAction",["some message that should be protocolled"]);
> ...
> }
>
> Is there some neater way to do this? (I started reading into the "Chains" topic but do not know if this protocolling mechanismn would be the right use case for chaining.)

I am not entirely sure that I understand what you mean by protocol
action - but how about a plain old method call:

MyApp::Controller::Root->myProtocolAction( $c, "some message that
should be protocolled" );


--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


catalyst4 at augensalat

Sep 9, 2009, 1:35 PM

Post #3 of 8 (1607 views)
Permalink
Re: best practice for a protocol mechanism? [In reply to]

Zbigniew Lukasiak wrote:

> I am not entirely sure that I understand what you mean by protocol
> action - but how about a plain old method call:
>
> MyApp::Controller::Root->myProtocolAction( $c, "some message that
> should be protocolled" );

I think Jens is talking about logging (German: "protokollieren").

But without further detail from his side it's hard to give good advice,
I think.



_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


bobtfish at bobtfish

Sep 9, 2009, 5:41 PM

Post #4 of 8 (1599 views)
Permalink
Re: best practice for a protocol mechanism? [In reply to]

On 9 Sep 2009, at 21:35, Bernhard Graf wrote:

> Zbigniew Lukasiak wrote:
>
>> I am not entirely sure that I understand what you mean by protocol
>> action - but how about a plain old method call:
>>
>> MyApp::Controller::Root->myProtocolAction( $c, "some message that
>> should be protocolled" );
>
> I think Jens is talking about logging (German: "protokollieren").

I'm guesstimating that he means 'I end up with this template code at
the end of loads of my actions, which forwards somewhere with various
params'...

Which I'd guess _could maybe_ be accomplished in a neater way with an
ActionRole which said 'after execute => sub {..etc..'

> But without further detail from his side it's hard to give good
> advice,
> I think.

You said it, the above is pure speculation :)

Cheers
t0m


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


blacky6767 at gmx

Sep 10, 2009, 5:43 AM

Post #5 of 8 (1587 views)
Permalink
Re: best practice for a protocol mechanism? [In reply to]

Oh, *err* right. I meant 'logging' and not 'protocol' *douh*.

Well, right now I have a proto^Wlogging action in my Root controller that I call everytime I want something to be logged in my DB.
P.ex.:

package MyApp::Controller::Book;
(...)
sub create ... {
...
$c->forward("MyApp::Controller::Root","myLoggingAction",["some message that should be logged"]);
}

In addition to this, I have a logging controller, that simply displays the list of logged messages from the DB.

Think of something like:

| Timestamp | User | Action |
+------------------+--------+------------------+
| 2009-09-10 10:30 | foobar | created new book |

So the question is: Is there a neater way of doing this? Some kind of best practice?


-------- Original-Nachricht --------
> Datum: Thu, 10 Sep 2009 01:41:29 +0100
> Von: Tomas Doran <bobtfish [at] bobtfish>
> An: The elegant MVC web framework <catalyst [at] lists>
> Betreff: Re: [Catalyst] best practice for a protocol mechanism?

> I'm guesstimating that he means 'I end up with this template code at
> the end of loads of my actions, which forwards somewhere with various
> params'...

Now *I* am not entirely sure that I understand what you mean by this. :)

Jens

--
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


jshirley at gmail

Sep 10, 2009, 6:24 AM

Post #6 of 8 (1579 views)
Permalink
Re: best practice for a protocol mechanism? [In reply to]

On Thu, Sep 10, 2009 at 6:43 AM, Jens Schwarz <blacky6767 [at] gmx> wrote:

> Oh, *err* right. I meant 'logging' and not 'protocol' *douh*.
>
> Well, right now I have a proto^Wlogging action in my Root controller that I
> call everytime I want something to be logged in my DB.
> P.ex.:
>
> package MyApp::Controller::Book;
> (...)
> sub create ... {
> ...
> $c->forward("MyApp::Controller::Root","myLoggingAction",["some message that
> should be logged"]);
> }
>
> In addition to this, I have a logging controller, that simply displays the
> list of logged messages from the DB.
>
> Think of something like:
>
> | Timestamp | User | Action |
> +------------------+--------+------------------+
> | 2009-09-10 10:30 | foobar | created new book |
>
> So the question is: Is there a neater way of doing this? Some kind of best
> practice?
>
>
Hi Jens,

I would do one of two things.

The first is to build a custom Catalyst::Log class if that is what you are
looking for, or you could even just use Catalyst::Log::Log4perl and
configure it as necessary. (Using Catalyst::Log::Log4perl is what I would
use).

Then, simply use $c->log->whatever.

The other option is to create a model for this, and change the code to:

$c->model('Logger')->log("Message");

If you use the model approach, you can use
Catalyst::Component::ACCEPT_CONTEXT to access $c->model('Schema') and
$c->user.

-J


jshirley at gmail

Sep 10, 2009, 6:26 AM

Post #7 of 8 (1580 views)
Permalink
Re: best practice for a protocol mechanism? [In reply to]

On Thu, Sep 10, 2009 at 7:24 AM, J. Shirley <jshirley [at] gmail> wrote:

>
>
> If you use the model approach, you can use
> Catalyst::Component::ACCEPT_CONTEXT to access $c->model('Schema') and
> $c->user.
>

Err, Catalyst::Component::InstancePerContext is the right one.

Don't mind me, I'm still thinking it is 2004.


alexander.hartmaier at t-systems

Sep 14, 2009, 4:44 AM

Post #8 of 8 (1482 views)
Permalink
Re: best practice for a protocol mechanism? [In reply to]

Sounds to me like an audit log which should be done by the model
regardless of where the model is used (e.g. Catalyst app, perl script
run by cron, ...).

That's the module you want imho:
http://search.cpan.org/~nuffin/DBIx-Class-Journal-0.900001_02/lib/DBIx/Class/Journal.pm

Am Donnerstag, den 10.09.2009, 14:43 +0200 schrieb Jens Schwarz:
> Oh, *err* right. I meant 'logging' and not 'protocol' *douh*.
>
> Well, right now I have a proto^Wlogging action in my Root controller that I call everytime I want something to be logged in my DB.
> P.ex.:
>
> package MyApp::Controller::Book;
> (...)
> sub create ... {
> ...
> $c->forward("MyApp::Controller::Root","myLoggingAction",["some message that should be logged"]);
> }
>
> In addition to this, I have a logging controller, that simply displays the list of logged messages from the DB.
>
> Think of something like:
>
> | Timestamp | User | Action |
> +------------------+--------+------------------+
> | 2009-09-10 10:30 | foobar | created new book |
>
> So the question is: Is there a neater way of doing this? Some kind of best practice?
>
>
> -------- Original-Nachricht --------
> > Datum: Thu, 10 Sep 2009 01:41:29 +0100
> > Von: Tomas Doran <bobtfish [at] bobtfish>
> > An: The elegant MVC web framework <catalyst [at] lists>
> > Betreff: Re: [Catalyst] best practice for a protocol mechanism?
>
> > I'm guesstimating that he means 'I end up with this template code at
> > the end of loads of my actions, which forwards somewhere with various
> > params'...
>
> Now *I* am not entirely sure that I understand what you mean by this. :)
>
> Jens
>
--
LG Alex


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.