| 1 | package Catalyst::Helper::Model::Adaptor; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Catalyst::Helper::Model::Adaptor - helper for the incredibly lazy | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | Running: | ||
| 12 | |||
| 13 | ./script/myapp_create.pl model SomeClass Adaptor MyApp::Backend::SomeClass create | ||
| 14 | |||
| 15 | Will create C<YourApp::Model::SomeClass> that looks like: | ||
| 16 | |||
| 17 | package YourApp::Model::SomeClass; | ||
| 18 | use strict; | ||
| 19 | use warnings; | ||
| 20 | use base 'Catalyst::Model::Adaptor'; | ||
| 21 | |||
| 22 | __PACKAGE__->config( | ||
| 23 | class => 'MyApp::Backend::SomeClass', | ||
| 24 | constructor => 'create', | ||
| 25 | ); | ||
| 26 | |||
| 27 | 1; | ||
| 28 | |||
| 29 | Why you need a script to generate that is beyond me, but here it is. | ||
| 30 | |||
| 31 | =head1 ARGUMENTS | ||
| 32 | |||
| 33 | ./script/myapp_create.pl model <model_name> Adaptor <class> [<constructor>] | ||
| 34 | |||
| 35 | You need to sepecify the C<model_name> (the name of the model), and | ||
| 36 | C<class>, the class being adapted. If C<< $class->new >> isn't going | ||
| 37 | to do what you want, pass the name of C<$class>'s constructor as | ||
| 38 | C<constructor>. | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | sub mk_compclass { | ||
| 43 | my ( $class, $helper, $adapted_class, $const ) = @_; | ||
| 44 | my ($type) = ($class =~ /^Catalyst::Helper::Model::(.+)$/); | ||
| 45 | die "i am nothing. that doesn't make sense." unless $type; | ||
| 46 | |||
| 47 | my %args = ( adapted_class => $adapted_class, | ||
| 48 | constructor => $const, | ||
| 49 | type => $type | ||
| 50 | ); | ||
| 51 | |||
| 52 | my $file = $helper->{file}; | ||
| 53 | $helper->render_file( 'compclass', $file, \%args ); | ||
| 54 | } | ||
| 55 | |||
| 56 | =head1 AUTHOR | ||
| 57 | |||
| 58 | Jonathan Rockway C<< <jrockway@cpan.org> >> | ||
| 59 | |||
| 60 | =head1 LICENSE | ||
| 61 | |||
| 62 | This library is free software. You can redistribute it and/or modify | ||
| 63 | it under the same terms as perl itself. | ||
| 64 | |||
| 65 | No copyright claim is asserted over the generated code. | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | 1; | ||
| 70 | |||
| 71 | __DATA__ |