/
MooseColumns.pm
163 lines (105 loc) · 3.71 KB
/
MooseColumns.pm
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package DBIx::Class::MooseColumns;
use Moose ();
use Moose::Exporter;
use Moose::Util::MetaRole;
use DBIx::Class::MooseColumns::Meta::Attribute;
Moose::Exporter->setup_import_methods();
sub init_meta {
my ($class, %args) = (shift, @_);
Moose->init_meta(%args);
Moose::Util::MetaRole::apply_metaroles(
for => $args{for_class},
class_metaroles => {
attribute => ['DBIx::Class::MooseColumns::Meta::Attribute'],
},
);
return $args{for_class}->meta;
}
=head1 NAME
DBIx::Class::MooseColumns - Lets you write DBIC add_column() definitions as attribute options
=head1 VERSION
Version 0.10
=cut
our $VERSION = '0.10';
=head1 SYNOPSIS
package MyApp::Schema::Result::Artist;
use Moose;
use DBIx::Class::MooseColumns;
use namespace::autoclean;
extends 'DBIx::Class::Core';
__PACKAGE__->table('artist');
has id => (
isa => 'Int',
is => 'rw',
add_column => {
is_auto_increment => 1,
},
);
has foo => (
isa => 'Str',
is => 'rw',
add_column => {
data_type => 'datetime'
},
);
has bar => ( # will call __PACKAGE__->add_column({})
isa => 'Str',
is => 'rw',
add_column => {
},
);
has quux => ( # no __PACKAGE__->add_column() call
isa => 'Str',
is => 'rw',
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->meta->make_immutable( inline_constructor => 0 );
1;
=head1 DISCLAIMER
This is ALPHA SOFTWARE. Use at your own risk. Features may change.
=head1 DESCRIPTION
This module allows you to put the arguments to
L<DBIx::Class::ResultSource/add_column> right into your attribute definitions
and will automatically call it when it finds an C<add_column> attribute option.
It also replaces the L<DBIx::Class>-generated accessor methods (these are
L<Class::Accessor::Grouped>-generated accessor methods under the hood) with the
L<Moose>-generated accessor methods so that you can use more of the wonderful
powers of L<Moose> (eg. type constraints, triggers, ...).
I<Note:> C<< __PACKAGE__->table(...) >> must go B<before> the C<has> stanzas
(the L<DBIx::Class::ResultSource/table> is magic and does much more than
setting the table name, thus the C<< __PACKAGE__->add_column(...) >> calls that
the C<has> triggers won't work before that).
I<Note:> C<< __PACKAGE__->set_primary_key(...) >> and C<<
__PACKAGE__->add_unique_constraint(...) >> calls must go B<after> the C<has>
stanzas (since they depend on the referred columns being registered via C<<
__PACKAGE__->add_column(...) >> and that call is done when the C<has> runs).
=head1 SEE ALSO
L<DBIx::Class>, L<Moose>
=head1 AUTHOR
Norbert Buchmuller, C<< <norbi at nix.hu> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-dbix-class-moosecolumns at
rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-MooseColumns>. I
will be notified, and then you'll automatically be notified of progress on your
bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc DBIx::Class::MooseColumns
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-MooseColumns>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/DBIx-Class-MooseColumns>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/DBIx-Class-MooseColumns>
=item * Search CPAN
L<http://search.cpan.org/dist/DBIx-Class-MooseColumns/>
=back
=head1 COPYRIGHT & LICENSE
Copyright 2010 Norbert Buchmuller, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1; # End of DBIx::Class::MooseColumns