File: Adaptor.pm

package info (click to toggle)
libcatalyst-model-adaptor-perl 0.10-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 284 kB
  • sloc: perl: 1,750; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package Catalyst::Helper::Model::Adaptor;
use strict;
use warnings;

=head1 NAME

Catalyst::Helper::Model::Adaptor - helper for the incredibly lazy

=head1 SYNOPSIS

Running:

    ./script/myapp_create.pl model SomeClass Adaptor MyApp::Backend::SomeClass create

Will create C<YourApp::Model::SomeClass> that looks like:

    package YourApp::Model::SomeClass;
    use strict;
    use warnings;
    use base 'Catalyst::Model::Adaptor';
    
    __PACKAGE__->config( 
        class       => 'MyApp::Backend::SomeClass',
        constructor => 'create',
    );

    1;

Why you need a script to generate that is beyond me, but here it is.

=head1 ARGUMENTS

   ./script/myapp_create.pl model <model_name> Adaptor <class> [<constructor>]

You need to sepecify the C<model_name> (the name of the model), and
C<class>, the class being adapted.  If C<< $class->new >> isn't going
to do what you want, pass the name of C<$class>'s constructor as
C<constructor>.

=cut

sub mk_compclass {
    my ( $class, $helper, $adapted_class, $const ) = @_;
    my ($type) = ($class =~ /^Catalyst::Helper::Model::(.+)$/);
    die "i am nothing.  that doesn't make sense." unless $type;

    my %args = ( adapted_class => $adapted_class, 
                 constructor   => $const, 
                 type          => $type
               );
    
    my $file = $helper->{file};
    $helper->render_file( 'compclass', $file, \%args );
}

=head1 AUTHOR

Jonathan Rockway C<< <jrockway@cpan.org> >>

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as perl itself.

No copyright claim is asserted over the generated code.

=cut

1;

__DATA__

__compclass__
package [% class %];
use strict;
use warnings;
use base 'Catalyst::Model::[% type %]';

__PACKAGE__->config( 
    class       => '[% adapted_class || 'Fill::This::In' %]',
    constructor => '[% constructor   || 'new'%]',
);

1;