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

Mailing List Archive: Catalyst: Users

namespace problem

 

 

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


mohan at thebizmo

Nov 21, 2009, 12:34 AM

Post #1 of 8 (1289 views)
Permalink
namespace problem

Hi,

I tried to use "use parent 'MyApp::Controller::Root';"

instead of use parent 'Catalyst::Controller'; in all my other
controllers(for ex: User.pm).

The reason is that Root.pm is already inheriting Catalyst::Controller.

But when i do this catalyst dispatcher is considerting all controller
actions in my other controllers under namespace ''.

But if i declare __PACKAGE__->config->{namespace} = 'user'; its working as
expected.

my server debug logs are here http://scsys.co.uk:8001/36484

Do i need to explicitly define namespace in each and every controllers in
that case or is there any other way to achieve it?

Thank you.

Best Regards,
Mohan
--
View this message in context: http://old.nabble.com/namespace-problem-tp26454140p26454140.html
Sent from the Catalyst Web Framework mailing list archive at Nabble.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/


onken at houseofdesign

Nov 21, 2009, 1:35 AM

Post #2 of 8 (1237 views)
Permalink
Re: namespace problem [In reply to]

Am 21.11.2009 um 16:34 schrieb gutta:

>
> Hi,
>
> I tried to use "use parent 'MyApp::Controller::Root';"
>
> instead of use parent 'Catalyst::Controller'; in all my other
> controllers(for ex: User.pm).
>
> The reason is that Root.pm is already inheriting Catalyst::Controller.
>
> But when i do this catalyst dispatcher is considerting all controller
> actions in my other controllers under namespace ''.
>
> But if i declare __PACKAGE__->config->{namespace} = 'user'; its working as
> expected.

You can try to set it to undef, so that the controller namespace magic can happen.
But not sure if this is working. Worth a try, though.

A better solution would be to create a base class MyApp::Controller::Base which does not set the namespace so that you only need to set it in the root controller.

moritz
_______________________________________________
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/


andrew at cleverdomain

Nov 21, 2009, 2:00 AM

Post #3 of 8 (1232 views)
Permalink
Re: namespace problem [In reply to]

On Saturday 21 November 2009 02:34:07 am gutta wrote:
> Hi,
>
> I tried to use "use parent 'MyApp::Controller::Root';"
>
> instead of use parent 'Catalyst::Controller'; in all my other
> controllers(for ex: User.pm).
>
> The reason is that Root.pm is already inheriting Catalyst::Controller.
>
> But when i do this catalyst dispatcher is considerting all controller
> actions in my other controllers under namespace ''.
>
> But if i declare __PACKAGE__->config->{namespace} = 'user'; its working as
> expected.
>
> my server debug logs are here http://scsys.co.uk:8001/36484
>
> Do i need to explicitly define namespace in each and every controllers in
> that case or is there any other way to achieve it?
>
For the sake of sanity, what you need to do is stop inheriting from a concrete
controller. It really doesn't make a lot of sense and there are a lot of ways
it could break something. As Moritz writes, if you need a controller base
class, write a controller base class and inherit from that.

Andrew

_______________________________________________
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/


mohan at thebizmo

Nov 21, 2009, 5:46 AM

Post #4 of 8 (1226 views)
Permalink
Re: namespace problem [In reply to]

Moritz Onken wrote:
>
>
> Am 21.11.2009 um 16:34 schrieb gutta:
>
>>
>> Hi,
>>
>> I tried to use "use parent 'MyApp::Controller::Root';"
>>
>> instead of use parent 'Catalyst::Controller'; in all my other
>> controllers(for ex: User.pm).
>>
>> The reason is that Root.pm is already inheriting Catalyst::Controller.
>>
>> But when i do this catalyst dispatcher is considerting all controller
>> actions in my other controllers under namespace ''.
>>
>> But if i declare __PACKAGE__->config->{namespace} = 'user'; its working
>> as
>> expected.
>
> You can try to set it to undef, so that the controller namespace magic can
> happen.
> But not sure if this is working. Worth a try, though.
>
> A better solution would be to create a base class MyApp::Controller::Base
> which does not set the namespace so that you only need to set it in the
> root controller.
>
> moritz
> _______________________________________________
> 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/
>
>

Hi Mortiz,
Thank you for your response.

So you want me to write a MyApp/lib/Controller/Base.pm as follows.

package MyApp::Controller::Base;

use strict;
use warnings;

use parent 'Catalyst::Controller';

#
# Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm
#

=head1 NAME

MyApp::Controller::Base - Base Controller for MyApp

=head1 DESCRIPTION

[enter your description here]

=cut

1;

and will do "use parent 'MyApp::Controller::Base';" instead of my previous
statement "use parent 'MyApp::Controller::Root';"

Thank you.

Best Regards,
Mohan
--
View this message in context: http://old.nabble.com/namespace-problem-tp26454140p26456702.html
Sent from the Catalyst Web Framework mailing list archive at Nabble.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/


peter at peknet

Nov 21, 2009, 10:55 AM

Post #5 of 8 (1220 views)
Permalink
Re: namespace problem [In reply to]

gutta wrote on 11/21/09 7:46 AM:

>
> So you want me to write a MyApp/lib/Controller/Base.pm as follows.
>
> package MyApp::Controller::Base;
>
> use strict;
> use warnings;
>
> use parent 'Catalyst::Controller';
>
> #
> # Sets the actions in this controller to be registered with no prefix
> # so they function identically to actions created in MyApp.pm
> #
>
> =head1 NAME
>
> MyApp::Controller::Base - Base Controller for MyApp
>
> =head1 DESCRIPTION
>
> [enter your description here]
>
> =cut
>
> 1;
>
> and will do "use parent 'MyApp::Controller::Base';" instead of my previous
> statement "use parent 'MyApp::Controller::Root';"
>


I think you want to keep stuff out of MyApp::Controller::* namespace unless you
want it instantiated at app startup.

Instead, create MyApp::Base::Controller and inherit from that in your
MyApp::Controller::* classes.

Otherwise, yes, you've got the idea.
--
Peter Karman . http://peknet.com/ . peter [at] peknet

_______________________________________________
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/


edencardim at gmail

Nov 24, 2009, 7:55 PM

Post #6 of 8 (1133 views)
Permalink
Re: namespace problem [In reply to]

>>>>> "Andrew" == Andrew Rodland <andrew [at] cleverdomain> writes:

Andrew> For the sake of sanity, what you need to do is stop
Andrew> inheriting from a concrete controller. It really doesn't
Andrew> make a lot of sense and there are a lot of ways it could
Andrew> break something. As Moritz writes, if you need a controller
Andrew> base class, write a controller base class and inherit from
Andrew> that.

Or even better, write a role instead.

--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://edenc.vox.com/ http://www.shadowcat.co.uk/servers/


_______________________________________________
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/


orasnita at gmail

Nov 25, 2009, 2:54 AM

Post #7 of 8 (1136 views)
Permalink
Re: namespace problem [In reply to]

From: "Eden Cardim" <edencardim [at] gmail>
>>>>>> "Andrew" == Andrew Rodland <andrew [at] cleverdomain> writes:
>
> Andrew> For the sake of sanity, what you need to do is stop
> Andrew> inheriting from a concrete controller. It really doesn't
> Andrew> make a lot of sense and there are a lot of ways it could
> Andrew> break something. As Moritz writes, if you need a controller
> Andrew> base class, write a controller base class and inherit from
> Andrew> that.
>
> Or even better, write a role instead.


Is there any tutorial for using Moose roles in Catalyst?

Thanks.

Octavian


_______________________________________________
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

Nov 25, 2009, 5:14 AM

Post #8 of 8 (1124 views)
Permalink
Re: namespace problem [In reply to]

Octavian Râsnita wrote:
> Is there any tutorial for using Moose roles in Catalyst?

http://search.cpan.org/~flora/Catalyst-Runtime-5.80014/lib/Catalyst/Upgrading.pod#Moose_features

http://search.cpan.org/~hkclark/Catalyst-Manual-5.8002/lib/Catalyst/Manual/CatalystAndMoose.pod

http://search.cpan.org/~flora/Moose-0.93/lib/Moose/Manual/Roles.pod


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/

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.