best practice for a protocol mechanism?

View: New views
8 Messages — Rating Filter:   Alert me  

best practice for a protocol mechanism?

by Jens Schwarz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: best practice for a protocol mechanism?

by Zbigniew Lukasiak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Sep 8, 2009 at 10:32 AM, Jens Schwarz<blacky6767@...> 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@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: best practice for a protocol mechanism?

by Bernhard Graf-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: best practice for a protocol mechanism?

by Tomas Doran :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: best practice for a protocol mechanism?

by Jens Schwarz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...>
> An: The elegant MVC web framework <catalyst@...>
> 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@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: best practice for a protocol mechanism?

by J. Shirley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Sep 10, 2009 at 6:43 AM, Jens Schwarz <blacky6767@...> 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

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

Re: best practice for a protocol mechanism?

by J. Shirley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Sep 10, 2009 at 7:24 AM, J. Shirley <jshirley@...> 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.

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

Re: best practice for a protocol mechanism?

by Alexander Hartmaier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...>
> > An: The elegant MVC web framework <catalyst@...>
> > 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@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/