Re: [Catalyst] How to execute controller at startup
Hi All, Thank you very much for all your valuable comments at appreciate your quick response. I have one more query. I have implemented a Plugin. How can I call a plugin method from controller outside of the controller methods. suppose i have a Plugin named Catalyst::Plugin::MyPlugin contains a method called sub myFunc {} Now i want to call myFunc from controller but i dont have context object outside of methods so currently I am doing: Catalyst::Plugin::MyPlugin::myFunc(); which is a normal function call (not catalyst way of doing, not even object oriented). Could you please suggest me an efficient way to call that method. Thanks, Aditya On 8/6/07, John Napiorkowski [EMAIL PROTECTED] wrote: --- Aditya Verma [EMAIL PROTECTED] wrote: Hi, I am new to catalyst. I have developed an application using Catalyst. I need all my controllers to execute at startup and register there method URLs. I am not getting how to execute controller at startup. Please help me. Thanks, Aditya Hi, Catalyst Controllers are subclasses of Catalyst::Component so are automatically located a registered by your primary Catalyst class at startup. If you are finding that you don't see your controllers and/or actions in the debug screen when you start the development server then you must have some typos in the controller package names or something similar. Please give us a little more detail about your trouble and the actually need that you are trying to fill. --john Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=listsid=396545433 ___ 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/
[Catalyst] TT macro to avoid excessive $c-uri_for calls
I'm wondering if it has any bad side effects to have a TT macro which is set to $c-uri_for. If I'm remembering previous posts on this topic correctly, calling uri_for() repeatedly has quite a big impact on performance which really matters most for my current application. I have this in a global macros.tt2 file: [% base = Catalyst.req.base; static = Catalyst.config.hosts.static; images = Catalyst.config.hosts.images; site.url = { base= base static = static images = images } -%] That way I can easily change the location of my static files and images to another server or place using the Catalyst config file and generate links like this: img src=[% site.url.images %]logo.png / a href=[% site.url.base %]user/whateverbla/a etc. Any comments? Thanks! --Tobias ___ 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] overload/override sub? (Session::PerUser)
On Mon, Aug 06, 2007 at 09:42:28PM +0100, Ash Berlin wrote: Fernan Aguero wrote: Hi, I'd like to overload (or would it be override?) the merge_session_to_user sub in Catalyst::Plugin::Session::PerUser to be able to guide the hash merge (i.e. create new hash value keys for conflicting keys). Now, where and how should I do the overriding? Excuse my ignorance ... but I've never done this and searching for 'Perl overload' always gets me to instructions on how to overload built-in operators ... Thanks in advance, Fernan Redefine is the term in perl-lingua. Not really, it's just subclassing. Catalyst plugins (like DBIC components) just end up as extra superclasses In MyApp.pm: { no warnings 'redefine'; # this line is completely pointless. sub merge_session_to_user { # your new sub # ... # To call the previous implementation if you should want it: # $self-NEXT::merge_session_to_user(@args); } } The key thing to remember here is that all Cat plugins 'pollute' the $c namespace, which isa Myapp. They end up on your @ISA, this polluting the namespace of potential method names, but they don't pollute the MyApp package directly - that level of stupidity I haven't seen since Class::DBI::Plugin::* -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical DirectorWant a managed development or deployment platform? Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote http://chainsawblues.vox.com/http://www.shadowcat.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] TT macro to avoid excessive $c-uri_for calls
On Tue, Aug 07, 2007 at 09:43:30AM +0200, Tobias Kremer wrote: I'm wondering if it has any bad side effects to have a TT macro which is set to $c-uri_for. If I'm remembering previous posts on this topic correctly, calling uri_for() repeatedly has quite a big impact on performance which really matters most for my current application. I have this in a global macros.tt2 file: That's why we optimised the living crap out of uri_for. It's more than 10x faster than it used to be. -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical DirectorWant a managed development or deployment platform? Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote http://chainsawblues.vox.com/http://www.shadowcat.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] Reseting a chained action
On Tue, Aug 07, 2007 at 10:13:59AM +0100, Pedro Melo wrote: Hi, In the course of a project I'm working on, I found it useful to reset chained actions. It would work like this: . assume that you have a chain like /company/ID/copywrongs . and in certain situations you want a alternative environment for the chain, like this: /approve/company/ID/copywrongs The /approve would modify the stash to include some alternative schema or environment that the rest of the chain could use to tweak their behavior. The thing is, the /approve action would like to tell catalyst ei, please disregard me and start over. Wouldn't it be simpler to have two parallel chains via subclassing, one set chained off '/' and one off the 'approve' action? -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical DirectorWant a managed development or deployment platform? Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote http://chainsawblues.vox.com/http://www.shadowcat.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] TT macro to avoid excessive $c-uri_for calls
On 8/7/07, Matt S Trout [EMAIL PROTECTED] wrote: That's why we optimised the living crap out of uri_for. It's more than 10x faster than it used to be. Great to hear that. Does it also apply to uri_with? -- Zbigniew Lukasiak http://brudnopis.blogspot.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] How to execute controller at startup
On Mon, Aug 06, 2007 at 11:33:04PM -0700, Aditya Verma wrote: Hi All, Thank you very much for all your valuable comments at appreciate your quick response. I have one more query. I have implemented a Plugin. How can I call a plugin method from controller outside of the controller methods. You shouldn't. If you need to do that, the method shouldn't be in a plugin. Don't hack up your Catalyst app, fix your design :) suppose i have a Plugin named Catalyst::Plugin::MyPlugin contains a method called sub myFunc {} That should be my_func, not myFunc. This is perl, not java. Please stick to the correct naming conventions for things. -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical DirectorWant a managed development or deployment platform? Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote http://chainsawblues.vox.com/http://www.shadowcat.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] How to execute controller at startup
--- Aditya Verma [EMAIL PROTECTED] wrote: Hi All, Thank you very much for all your valuable comments at appreciate your quick response. I have one more query. I have implemented a Plugin. How can I call a plugin method from controller outside of the controller methods. suppose i have a Plugin named Catalyst::Plugin::MyPlugin contains a method called sub myFunc {} Now i want to call myFunc from controller but i dont have context object outside of methods so currently I am doing: Catalyst::Plugin::MyPlugin::myFunc(); which is a normal function call (not catalyst way of doing, not even object oriented). Could you please suggest me an efficient way to call that method. Thanks, Aditya Since I'm not sure what your use case is I can only give you some vaguely general suggestions. First of all, the community has lately pushed people to look carefully at their plugins to see if they are really plugins or something else. There is a document posted at: http://search.cpan.org/~jrockway/Catalyst-Manual-5.700701/lib/Catalyst/Manual/ExtendingCatalyst.pod which is a a MUST READ for all new developers. If you have something locked up in a plugin that you need elsewhere, like in a cron job, for example, that probably belongs in a Plain old Perl class and brought into Catalyst via a Model. That way you can access functionality outside of Catalyst. For (very brief) example: A Plain Old Perl module: package Myapp::Somestuff; use base 'Class::Accessor'; sub stuff { my ($self, $arg) = @_; return $arg x 2; } A Catalyst model to wrap this: package Myapp::Web::Model::Somestuff; use Class::C3; use base 'Catalyst::Model'; __PACKAGE__-mk_accessors(qw/somestuff/); sub new { my ($class, $c, $arguments) = @_; my $self = $class-next::method($c, $arguments); $self-somestuff(Myapp::Somestuff-new()); return $self; } sub stuff { shift-somestuff-stuff(@_); } In a controller: Package Myapp::Web::Controller::Something; use base 'Catalyst::Controller'; sub testit :Local { my ($self, $c) = @_; $c-stash( result = $c-model('Somestuff')-stuff('a'), ); } And then in your template you have a stash key 'result' which is equal to 'aa'. And you have code you can use outside of catalyst. The above can be improved. For example you can use AUTOLOAD to automatically map the wrapper methods in your module: (Lifted pretty much from Handle or Mango, I forgot) sub AUTOLOAD { my $self = shift @_; my @args = @_; my ($method) = (our $AUTOLOAD =~ /([^:]+)$/); return if $method =~ /(DESTROY|ACCEPT_CONTEXT)/; return $self-somestuff-$method(@args) if $self-somestuff-can($method); } Good luck! -john On 8/6/07, John Napiorkowski [EMAIL PROTECTED] wrote: --- Aditya Verma [EMAIL PROTECTED] wrote: Hi, I am new to catalyst. I have developed an application using Catalyst. I need all my controllers to execute at startup and register there method URLs. I am not getting how to execute controller at startup. Please help me. Thanks, Aditya Hi, Catalyst Controllers are subclasses of Catalyst::Component so are automatically located a registered by your primary Catalyst class at startup. If you are finding that you don't see your controllers and/or actions in the debug screen when you start the development server then you must have some typos in the controller package names or something similar. Please give us a little more detail about your trouble and the actually need that you are trying to fill. --john Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=listsid=396545433 ___ 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/ Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV. http://tv.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] TT macro to avoid excessive $c-uri_for calls
On Tue, Aug 07, 2007 at 01:10:09PM +, Zbigniew Lukasiak wrote: On 8/7/07, Matt S Trout [EMAIL PROTECTED] wrote: That's why we optimised the living crap out of uri_for. It's more than 10x faster than it used to be. Great to hear that. Does it also apply to uri_with? Nobody ever reported that as a bottleneck, and it's a much simpler code path already. -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical DirectorWant a managed development or deployment platform? Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote http://chainsawblues.vox.com/http://www.shadowcat.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] How to execute controller at startup
On Mon, Aug 06, 2007 at 11:33:04PM -0700, Aditya Verma wrote: Hi All, Thank you very much for all your valuable comments at appreciate your quick response. I have one more query. I have implemented a Plugin. How can I call a plugin method from controller outside of the controller methods. You shouldn't. If you need to do that, the method shouldn't be in a plugin. Don't hack up your Catalyst app, fix your design :) Expanding on what mst said, keep in mind that plugins are reserved for things that need to affect the request cycle. If you just need some functionality, write a regular module. If it needs $c, pass in $c. Component base classes are also possible, and are a better approach than plugins. (See C::Plugin::FormBuilder vs. C::Controller::FormBuilder. Both are on CPAN so you can compare the approaches.) Finally, phaylon's Extending Catalyst guide: http://search.cpan.org/~jrockway/Catalyst-Manual-5.700701/lib/Catalyst/Manual/ExtendingCatalyst.pod suppose i have a Plugin named Catalyst::Plugin::MyPlugin contains a method called sub myFunc {} That should be my_func, not myFunc. This is perl, not java. Please stick to the correct naming conventions for things. TMTOWTDI, but your way is rather unconventional. Identifiers should be lowercase (%karma_for), constants should be uppercase ($SECRET_OF_THE_UNIVERSE), and modules should be CamelCase (MyApp::SomeThing). Anything else will make people like mst mad because it's really really ugly. Hope this helps. Regards, Jonathan Rockway ___ 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/