[Catalyst] YA CRUD module
David Schmidt
davewood at gmx.at
Mon Dec 5 15:04:04 GMT 2011
I updated my code so it does pretty much what CatalystX::SimpleLogin does.
Namely to inject a Controller then applying or removing traits.
Unlike SimpleLogin I want to be able to inject many Controllers.
here is what I came up with:
1 use Catalyst qw/+CatalystX::Resource/;
2
3 __PACKAGE__->config(
4 CatalystX::Resource => {
5 controllers => {
6 Artist => {
7 resultset_key => 'artists_rs',
8 resources_key => 'artists',
9 resource_key => 'artist',
10 model => 'DB:Artists',
11 traits => ['-Delete'],
12 },
13 Song => {
14 parent_key => 'artist',
15 parents_accessor => 'songs',
16 resources_key => 'songs',
17 resource_key => 'song',
18 model => 'DB::Songs',
19 },
20 },
21 },
22 );
23
24 after 'setup_components' => sub {
25 my $class = shift;
26 my $controllers
27 = $class->config->{'CatalystX::Resource'}{'controllers'};
28 while (my ($controller, $config) = each(%$controllers)) {
29 CatalystX::InjectComponent->inject(
30 into => $class,
31 component => 'CatalystX::Resource::Controller::Resource',
32 as => 'Controller::Resource::' . $controller,
33 );
34 }
35 };
I wonder if it works. will test it when i have the time.
On 5 December 2011 12:51, David Schmidt <davewood at gmx.at> wrote:
> Here is a simple testcase of what I did. Once i noticed that i
> required a method defined in the same role it made sense.
>
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
> use Test::More;
>
> {
> package MyRole;
> use Moose::Role;
>
> requires 'a';
> has a => (is => 'rw');
> }
>
> {
> package MyClass;
> use Moose;
> with 'MyRole';
> }
>
> my $foo = MyClass->new({ a => 'foo' });
> can_ok ($foo, 'a');
>
> done_testing;
>
>
> 'MyRole' requires the method 'a' to be implemented by 'MyClass' at
> /usr/local/lib/perl/5.10.1/Moose/Meta/Role/Application.pm line 53
> Moose::Meta::Role::Application::apply('Moose::Meta::Role::Application::ToClass=HASH(0x9dc5a78)',
> 'Moose::Meta::Role=HASH(0x9dc55e8)',
> 'Moose::Meta::Class=HASH(0x9ce8170)') called at
> /usr/local/lib/perl/5.10.1/Moose/Meta/Role/Application/ToClass.pm line
> 33
> Moose::Meta::Role::Application::ToClass::apply('Moose::Meta::Role::Application::ToClass=HASH(0x9dc5a78)',
> 'Moose::Meta::Role=HASH(0x9dc55e8)',
> 'Moose::Meta::Class=HASH(0x9ce8170)', 'HASH(0x9c817c8)') called at
> /usr/local/lib/perl/5.10.1/Moose/Meta/Role.pm line 482
> Moose::Meta::Role::apply('Moose::Meta::Role=HASH(0x9dc55e8)',
> 'Moose::Meta::Class=HASH(0x9ce8170)') called at
> /usr/local/lib/perl/5.10.1/Moose/Util.pm line 154
> Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x9ce8170)',
> undef, 'MyRole') called at /usr/local/lib/perl/5.10.1/Moose/Util.pm
> line 93
> Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x9ce8170)',
> 'MyRole') called at /usr/local/lib/perl/5.10.1/Moose.pm line 65
> Moose::with('Moose::Meta::Class=HASH(0x9ce8170)', 'MyRole')
> called at /usr/local/lib/perl/5.10.1/Moose/Exporter.pm line 356
> Moose::with('MyRole') called at ./test.pl line 18
>
>
>
> On 5 December 2011 11:58, Tomas Doran <bobtfish at bobtfish.net> wrote:
>>
>> On 4 Dec 2011, at 23:46, David Schmidt wrote:
>>
>>> just thought i'll keep you up to day so you dont waste time trying to
>>> help with a problem i already solved.
>>>
>>> Turns out the error cause was in one of the roles. It required a
>>> method declared in the same role.
>>
>>
>> This has to be a Moose bug in some way.
>>
>> Moose should be able to complain that you are requiring a method you've
>> already provided, and/or it shouldn't fail.
>>
>> Any chance of a small(ish) test case for this one?
>>
>>
>> Cheers
>> t0m
>>
>>
>> _______________________________________________
>> List: Catalyst at lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
More information about the Catalyst
mailing list