Re: [Catalyst] Accessing $c from Model

2007-03-06 Thread Scott Thomson

Excellent, that works - Thank you!

On 3/5/07, Juan Miguel Paredes [EMAIL PROTECTED] wrote:

On 3/5/07, Scott Thomson [EMAIL PROTECTED] wrote:
 Ok, I think I'm close...

 My main schema class:

 package DB;

 use base qw/DBIx::Class::Schema  DBIx::Class::AccessorGroup/;

 __PACKAGE__-mk_group_accessors(simple = 'context');
 __PACKAGE__-load_classes(qw//);
 1;


 My model class...

 package WCN::Model::DB;

 use strict;
 use base qw/Catalyst::Model::DBIC::Schema::WCN/;

 __PACKAGE__-config(
 schema_class = 'DB',
 );

 sub ACCEPT_CONTEXT {
   my ($self, $c, @args) = @_;

   $c-log-debug(  *** class:  . ref($self));

   my $new = bless({%$self}, ref $self);
   $new-schema(bless({%{$self-schema}}, ref($self-schema)));
   $new-schema-context($c);

   # Outputs 'WCN' which is correct
   $c-log-debug(  *** ref of context in self: ,
 ref($new-schema-context()));

   return $new;
 }

 The debug prints the correct class of $c when ACCEPT_CONTEXT is
 called, however $self-result_source-schema-context is not present
 in the model objects.

 Have I got the wrong end of the stick somewhere?

 Many Thanks,

 Scott.

That looks very similar to what we did, but in the model class:

sub ACCEPT_CONTEXT {
  my ($self, $c, @args) = @_;

  my $new = bless({ %$self }, ref $self);
  $new-schema-_context($c);
  return $new;
}

(we used _context for accesor)

Also, I don't know if the DB namespace is reserved for debug, and
could lead to complications... I think I read that in a nearby thread
a while ago, but can't locate it right now...

Regards,
Juan.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-03-06 Thread Jason Kohles

On Mar 5, 2007, at 7:02 AM, Scott Thomson wrote:


Ok, I think I'm close...

My main schema class:

package DB;

use base qw/DBIx::Class::Schema  DBIx::Class::AccessorGroup/;

__PACKAGE__-mk_group_accessors(simple = 'context');
__PACKAGE__-load_classes(qw//);
1;

Very Bad Things are likely to happen if you ever attempt to run your  
application under the debugger when you have a package named 'DB'.   
I'd recommend using a different name...


--
Jason Kohles
[EMAIL PROTECTED]
http://www.jasonkohles.com/
A witty saying proves nothing.  -- Voltaire


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-03-06 Thread Scott Thomson

Noted and actioned,  Cheers.

Very Bad Things are likely to happen if you ever attempt to run your

application under the debugger when you have a package named 'DB'.  I'd
recommend using a different name...

--
Jason Kohles
[EMAIL PROTECTED]
http://www.jasonkohles.com/
A witty saying proves nothing.  -- Voltaire



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-03-05 Thread Juan Miguel Paredes

On 3/5/07, Scott Thomson [EMAIL PROTECTED] wrote:

Ok, I think I'm close...

My main schema class:

package DB;

use base qw/DBIx::Class::Schema  DBIx::Class::AccessorGroup/;

__PACKAGE__-mk_group_accessors(simple = 'context');
__PACKAGE__-load_classes(qw//);
1;


My model class...

package WCN::Model::DB;

use strict;
use base qw/Catalyst::Model::DBIC::Schema::WCN/;

__PACKAGE__-config(
schema_class = 'DB',
);

sub ACCEPT_CONTEXT {
  my ($self, $c, @args) = @_;

  $c-log-debug(  *** class:  . ref($self));

  my $new = bless({%$self}, ref $self);
  $new-schema(bless({%{$self-schema}}, ref($self-schema)));
  $new-schema-context($c);

  # Outputs 'WCN' which is correct
  $c-log-debug(  *** ref of context in self: ,
ref($new-schema-context()));

  return $new;
}

The debug prints the correct class of $c when ACCEPT_CONTEXT is
called, however $self-result_source-schema-context is not present
in the model objects.

Have I got the wrong end of the stick somewhere?

Many Thanks,

Scott.


That looks very similar to what we did, but in the model class:

sub ACCEPT_CONTEXT {
 my ($self, $c, @args) = @_;

 my $new = bless({ %$self }, ref $self);
 $new-schema-_context($c);
 return $new;
}

(we used _context for accesor)

Also, I don't know if the DB namespace is reserved for debug, and
could lead to complications... I think I read that in a nearby thread
a while ago, but can't locate it right now...

Regards,
Juan.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-02-27 Thread Scott Thomson

Hi,

This is exactly what I want to do, however I can't seem to get my head round
how to implement this solution, I've tried various incarnations but I don't
seem to be getting anywhere.

Annotations below, thanks for patience.

Scott


On 2/1/07, Juan Miguel Paredes [EMAIL PROTECTED] wrote:


On 2/1/07, Matt S Trout [EMAIL PROTECTED] wrote:

 package MyApp::DataStore; # or whatever this is called

 use base qw/DBIx::Class::Schema/;

 __PACKAGE__-mk_group_accessors(simple = 'context');




I get this bit, (also add DBIx::Class::AccessorGroup to the base class list)



then

 my $new = bless ...






 $new-schema(bless(...)); # same trick on the schema

 $new-schema-context($c);



Is the above in the same file? what should replace the ellipsis


then in the DBIC code

 $self-result_source-schema-context;

 make more sense?




Where exactly is the DBIC code? MyApp::Model::DataStore?

Indeed, your suggestion worked fine, thanks a lot!  Just had to add

DBIx::Class::AccessorGroup to the schema class

Regards,

Juan.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-02-01 Thread Matt S Trout


On 31 Jan 2007, at 19:27, Juan Miguel Paredes wrote:


On 1/31/07, Matt S Trout [EMAIL PROTECTED] wrote:


On 31 Jan 2007, at 15:23, Juan Miguel Paredes wrote:

 Hi, all!

 What if we have to overload ACCEPT_CONTEXT to do something like  
this,

 but using DBIC::Schema?  What would be the recommended inheritance
 chain? Catalyst::Model::DBIC::Schema acts as a glue between the  
actual
 Catalyst model and the Schema classes, so I'm a little confused  
about

 where to start...  In this particular case, we'd like to access $c
 from model in order to overload subroutines (trigger-like) to  
track,

 for example, which user modified what...

add an accessor to the schema, and do $schema-clone then hand that
$c-user



Ok! I understand that ACCEPT_CONTEXT would have to be placed in a
package along the Catalyst::Base inheritance chain, so, a feasible
place would be in MyApp::Model::Schema (based on
Catalyst::Model::DBIC::Schema).  I've tried this:


package MyApp::Model::BD;

use strict;
use base 'Catalyst::Model::DBIC::Schema';

__PACKAGE__-mk_accessors( 'context' );

sub ACCEPT_CONTEXT {
 my ($self, $c, @args) = @_;

 my $new = bless({ %$self }, ref $self);
 $new-context($c);

 return $new;
}


package MyApp::DataStore; # or whatever this is called

use base qw/DBIx::Class::Schema/;

__PACKAGE__-mk_group_accessors(simple = 'context');

then

my $new = bless ...

$new-schema(bless(...)); # same trick on the schema

$new-schema-context($c);

then in the DBIC code

$self-result_source-schema-context;

make more sense?

--
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for  
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for  
details.
+ Help us build a better perl ORM: http://dbix- 
class.shadowcatsystems.co.uk/ +




___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-02-01 Thread Juan Miguel Paredes

On 2/1/07, Matt S Trout [EMAIL PROTECTED] wrote:


package MyApp::DataStore; # or whatever this is called

use base qw/DBIx::Class::Schema/;

__PACKAGE__-mk_group_accessors(simple = 'context');

then

my $new = bless ...

$new-schema(bless(...)); # same trick on the schema

$new-schema-context($c);

then in the DBIC code

$self-result_source-schema-context;

make more sense?



Indeed, your suggestion worked fine, thanks a lot!  Just had to add
DBIx::Class::AccessorGroup to the schema class

Regards,

Juan.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-01-31 Thread Juan Miguel Paredes

On 12/27/06, Ash Berlin [EMAIL PROTECTED] wrote:

Mark Zealey wrote:
 Hi there,

 I'm basically wanting to write a simple log function which logs hits on my
 website as entries in a database (automatically adding $c-user-{id} and
 $c-req-referrer etc), but to do so I want to use a model (I think). Any
 ideas how I can just say $c-model('Log')-info(foo) and automatically get
 $c passed in? I think I could have sth like:

 package MyApp::Model::Log;
 use base 'Catalyst::Model';

 my $last_c;

 sub ACCEPT_CONTEXT {
   my ($self, $c) = @_;
   $last_c = $c;
 }

 sub info {
   my ($self, $msg) = @_
   my $c = $last_c;
   ...
 }

 but this seems pretty messy...

 Mark


Very very *VERY* bad idea.

__PACKAGE__-mk_accessors(context);

sub ACCEPT_CONTEXT {
   my ($self, $c, @args) = @_;

   my $new = bless({ %$self }, ref $self);
   $new-context($c);
   return $new;
}


Something like the above instead.

Ash


Hi, all!

What if we have to overload ACCEPT_CONTEXT to do something like this,
but using DBIC::Schema?  What would be the recommended inheritance
chain? Catalyst::Model::DBIC::Schema acts as a glue between the actual
Catalyst model and the Schema classes, so I'm a little confused about
where to start...  In this particular case, we'd like to access $c
from model in order to overload subroutines (trigger-like) to track,
for example, which user modified what...

Thanks in advance,

Juan.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-01-31 Thread Matt S Trout


On 31 Jan 2007, at 15:23, Juan Miguel Paredes wrote:


On 12/27/06, Ash Berlin [EMAIL PROTECTED] wrote:

Mark Zealey wrote:
 Hi there,

 I'm basically wanting to write a simple log function which logs  
hits on my
 website as entries in a database (automatically adding $c-user- 
{id} and
 $c-req-referrer etc), but to do so I want to use a model (I  
think). Any
 ideas how I can just say $c-model('Log')-info(foo) and  
automatically get

 $c passed in? I think I could have sth like:

 package MyApp::Model::Log;
 use base 'Catalyst::Model';

 my $last_c;

 sub ACCEPT_CONTEXT {
   my ($self, $c) = @_;
   $last_c = $c;
 }

 sub info {
   my ($self, $msg) = @_
   my $c = $last_c;
   ...
 }

 but this seems pretty messy...

 Mark


Very very *VERY* bad idea.

__PACKAGE__-mk_accessors(context);

sub ACCEPT_CONTEXT {
   my ($self, $c, @args) = @_;

   my $new = bless({ %$self }, ref $self);
   $new-context($c);
   return $new;
}


Something like the above instead.

Ash


Hi, all!

What if we have to overload ACCEPT_CONTEXT to do something like this,
but using DBIC::Schema?  What would be the recommended inheritance
chain? Catalyst::Model::DBIC::Schema acts as a glue between the actual
Catalyst model and the Schema classes, so I'm a little confused about
where to start...  In this particular case, we'd like to access $c
from model in order to overload subroutines (trigger-like) to track,
for example, which user modified what...


add an accessor to the schema, and do $schema-clone then hand that  
$c-user


--
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for  
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for  
details.
+ Help us build a better perl ORM: http://dbix- 
class.shadowcatsystems.co.uk/ +




___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2007-01-31 Thread Juan Miguel Paredes

On 1/31/07, Matt S Trout [EMAIL PROTECTED] wrote:


On 31 Jan 2007, at 15:23, Juan Miguel Paredes wrote:

 Hi, all!

 What if we have to overload ACCEPT_CONTEXT to do something like this,
 but using DBIC::Schema?  What would be the recommended inheritance
 chain? Catalyst::Model::DBIC::Schema acts as a glue between the actual
 Catalyst model and the Schema classes, so I'm a little confused about
 where to start...  In this particular case, we'd like to access $c
 from model in order to overload subroutines (trigger-like) to track,
 for example, which user modified what...

add an accessor to the schema, and do $schema-clone then hand that
$c-user



Ok! I understand that ACCEPT_CONTEXT would have to be placed in a
package along the Catalyst::Base inheritance chain, so, a feasible
place would be in MyApp::Model::Schema (based on
Catalyst::Model::DBIC::Schema).  I've tried this:


package MyApp::Model::BD;

use strict;
use base 'Catalyst::Model::DBIC::Schema';

__PACKAGE__-mk_accessors( 'context' );

sub ACCEPT_CONTEXT {
 my ($self, $c, @args) = @_;

 my $new = bless({ %$self }, ref $self);
 $new-context($c);

 return $new;
}

In fact, placing some $c-log-debug in ACCEPT_CONTEXT shows it runs
ok. The question is, if this is the right place to overload
ACCEPT_CONTEXT, how would I access the context from, say:

package MyApp::Schema::BD::TpRol;

use strict;
use base qw/DBIx::Class/;

#table, add_columns, etc.

sub update {
 my $self = shift;

 my $c = $self-context; # wrong, no method context, because $self
is a DBIx::Class::Row

 my $c = MyApp::Model::BD-context; # wrong, complains that Can't use
string (MyApp::Model::BD) as a HASH ref while strict refs

 return $self-next::method( @_ );
}


So, if the location for overloading ACCEPT_CONTEXT seems reasonable,
accessing it from overloaded subroutines in ResultSource would be the
last part of the puzzle.  In this case, just as a proof of concept,
I'm trying to access the whole $c, but later that could be refined
with accessors for, say, just $c-user, $c-request-params, etc.

Thanks again!

Juan

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2006-12-27 Thread Lorn

you can passa the $c from controller to model
$c-model(foo)-bar($c,$foobar);

On 12/27/06, Mark Zealey [EMAIL PROTECTED] wrote:


Hi there,

I'm basically wanting to write a simple log function which logs hits on my
website as entries in a database (automatically adding $c-user-{id} and
$c-req-referrer etc), but to do so I want to use a model (I think). Any
ideas how I can just say $c-model('Log')-info(foo) and automatically
get
$c passed in? I think I could have sth like:

package MyApp::Model::Log;
use base 'Catalyst::Model';

my $last_c;

sub ACCEPT_CONTEXT {
my ($self, $c) = @_;
$last_c = $c;
}

sub info {
my ($self, $msg) = @_
my $c = $last_c;
...
}

but this seems pretty messy...

Mark

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/





--
Lorn
- Slackware Linux
www.slackwarezine.com.br
- http://lornlab.org
___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2006-12-27 Thread Ash Berlin

Mark Zealey wrote:

Hi there,

I'm basically wanting to write a simple log function which logs hits on my 
website as entries in a database (automatically adding $c-user-{id} and 
$c-req-referrer etc), but to do so I want to use a model (I think). Any 
ideas how I can just say $c-model('Log')-info(foo) and automatically get 
$c passed in? I think I could have sth like:


package MyApp::Model::Log;
use base 'Catalyst::Model';

my $last_c;

sub ACCEPT_CONTEXT {
my ($self, $c) = @_;
$last_c = $c;
}

sub info {
my ($self, $msg) = @_
my $c = $last_c;
...
}

but this seems pretty messy...

Mark



Very very *VERY* bad idea.

__PACKAGE__-mk_accessors(context);

sub ACCEPT_CONTEXT {
  my ($self, $c, @args) = @_;

  my $new = bless({ %$self }, ref $self);
  $new-context($c);
  return $new;
}


Something like the above instead.

Ash

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2006-12-27 Thread John Napiorkowski

--- Lorn [EMAIL PROTECTED] wrote:

 you can passa the $c from controller to model
 $c-model(foo)-bar($c,$foobar);

I'd vote for this method over setting the context,
since one of the goals of a model is to not care about
how or when it's called, that way you are encouraging
yourself to not build a fragile application where
everything is interdependent.  Actually I'd take it a
step further and only pass the stuff from the context
that you need, like $c-request if you need the
request object, etc.

That being said I have used the method suggested by
another responder for grabbing the context, mostly so
that I can do debugging inside the model
($c-log-...).  If there was better way to access the
log object from views and models that don't require
getting the context or getting $c-log than I am sure
I'd never need it.

A seemless way to share $c-log with DBIx::Class
objects would also be nice.

Also, as an aside, if you are building a custom logger
it might be more fun to create your own logger object
so that you can do $c-log-mylogger(...), or I
believe you can use the Log4Perl catalyst plugin and
configure it to log to a databse.  That way you can
skip the whole creating a custom model for this need.

--john

 
 On 12/27/06, Mark Zealey [EMAIL PROTECTED] wrote:
 
  Hi there,
 
  I'm basically wanting to write a simple log
 function which logs hits on my
  website as entries in a database (automatically
 adding $c-user-{id} and
  $c-req-referrer etc), but to do so I want to use
 a model (I think). Any
  ideas how I can just say
 $c-model('Log')-info(foo) and automatically
  get
  $c passed in? I think I could have sth like:
 
  package MyApp::Model::Log;
  use base 'Catalyst::Model';
 
  my $last_c;
 
  sub ACCEPT_CONTEXT {
  my ($self, $c) = @_;
  $last_c = $c;
  }
 
  sub info {
  my ($self, $msg) = @_
  my $c = $last_c;
  ...
  }
 
  but this seems pretty messy...
 
  Mark
 
  ___
  List: Catalyst@lists.rawmode.org
  Listinfo:
 http://lists.rawmode.org/mailman/listinfo/catalyst
  Searchable archive:
 

http://www.mail-archive.com/catalyst@lists.rawmode.org/
  Dev site: http://dev.catalyst.perl.org/
 
 
 
 
 -- 
 Lorn
 - Slackware Linux
 www.slackwarezine.com.br
 - http://lornlab.org
  ___
 List: Catalyst@lists.rawmode.org
 Listinfo:
 http://lists.rawmode.org/mailman/listinfo/catalyst
 Searchable archive:

http://www.mail-archive.com/catalyst@lists.rawmode.org/
 Dev site: http://dev.catalyst.perl.org/
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2006-12-27 Thread Mark Zealey
On Wednesday 27 December 2006 1:01 pm, Ash Berlin wrote:
 Very very *VERY* bad idea.

 __PACKAGE__-mk_accessors(context);

 sub ACCEPT_CONTEXT {
my ($self, $c, @args) = @_;

my $new = bless({ %$self }, ref $self);
$new-context($c);
return $new;
 }

Isn't that really really slow though? Constructing a new object for each call?

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2006-12-27 Thread Eden Cardim

On 12/27/06, Mark Zealey [EMAIL PROTECTED] wrote:

Hi there,

I'm basically wanting to write a simple log function which logs hits on my
website as entries in a database (automatically adding $c-user-{id} and
$c-req-referrer etc), but to do so I want to use a model (I think). Any
ideas how I can just say $c-model('Log')-info(foo) and automatically get
$c passed in?


What's wrong with $c-forward('Model::Log', 'info', ['foo']) ?

--
Eden Cardim
Instituto Baiano de Biotecnologia
Núcleo de Biologia Computacional e Gestão de Informações Biotecnológicas
Laboratório de Bioinformática
--
you seem to think that 'close enough' is close enough...
please learn to be 'literal' around programming.
merlyn - on irc.freenode.net#perl

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2006-12-27 Thread Jonathan Rockway
 Isn't that really really slow though? Constructing a new object for each call?

No, it's not.  Creating an object in Perl amounts to setting a flag (the
OBJECT flag in subclasses of SvPVMG, to be exact).

See illguts: http://gisle.aas.no/perl/illguts/

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)-config(name = do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
;$;]-[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;-setup;

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Accessing $c from Model

2006-12-27 Thread John Napiorkowski

--- Eden Cardim [EMAIL PROTECTED] wrote:

 On 12/27/06, Mark Zealey [EMAIL PROTECTED] wrote:
  Hi there,
 
  I'm basically wanting to write a simple log
 function which logs hits on my
  website as entries in a database (automatically
 adding $c-user-{id} and
  $c-req-referrer etc), but to do so I want to use
 a model (I think). Any
  ideas how I can just say
 $c-model('Log')-info(foo) and automatically get
  $c passed in?
 
 What's wrong with $c-forward('Model::Log', 'info',
 ['foo']) ?

This discussion is bring back old nightmares for me :)
 Catalyst is really flexible but I personally haven't
really figured out the value of:

## Forward style
$c-forward('Model::Log', 'info', ['foo'])

versus

## direct invocation style
$c-model('Log')-info(foo) with/without using
ACCEPT_CONTEXT to have this instantiate a new object
for each request

versus 

## Classic Perl style
Use Model::Log;

my $log = Model::Log-new(...);
$log-info($c,'foo');

I tend to use forwarding mostly for controllers,
although with Chaining I find I need this less and
less.  I also use forward to delegate to a view
handler.

From what I can see the main advantage of forward is
that it sends the context for you automatically.  Also
you get the automatic return but this to me seems less
important with a model and more relevant to
controllers.  Usually my models return self or some
sort of value anyway.

The only advantage I can see for making your business
objects into catalyst models is that you get the handy
config methods that you can centralize in your main
configuration file if you like.  And it saves you
having to add 'use ...' at the top of all the
controllers that need a particular model (although you
can create a base controller to help with this issue).

I'm certainly offtopic by now but this question gets
asked of me by my coworkers and I wish I had more than
a list of pro/cons to give as an answer.

--john

 
 -- 
 Eden Cardim
 Instituto Baiano de Biotecnologia
 Núcleo de Biologia Computacional e Gestão de
 Informações Biotecnológicas
 Laboratório de Bioinformática
 --
 you seem to think that 'close enough' is close
 enough...
 please learn to be 'literal' around programming.
 merlyn - on irc.freenode.net#perl
 
 ___
 List: Catalyst@lists.rawmode.org
 Listinfo:
 http://lists.rawmode.org/mailman/listinfo/catalyst
 Searchable archive:

http://www.mail-archive.com/catalyst@lists.rawmode.org/
 Dev site: http://dev.catalyst.perl.org/
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/