Add support for nested hashref form of col_accessor_map
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Column.pm
1 package DBIx::Class::Schema::Loader::Column;
2
3 use strict;
4 use warnings;
5 use base 'Class::Accessor::Grouped';
6 use mro 'c3';
7 use Carp::Clan qw/^DBIx::Class/;
8 use Scalar::Util 'weaken';
9 use namespace::clean;
10
11 =head1 NAME
12
13 DBIx::Class::Schema::Loader::Column - Class for Columns in
14 L<DBIx::Class::Schema::Loader>
15
16 =head1 DESCRIPTION
17
18 Used for representing columns in
19 L<DBIx::Class::Schema::Loader::Base/col_accessor_map>.
20
21 Stringifies to L</name>, and arrayrefifies to the
22 L<name_parts|DBIx::Class::Schema::Loader::Table/name_parts> of
23 L</table> plus L</name>.
24
25 =cut
26
27 __PACKAGE__->mk_group_accessors(simple => qw/
28     table
29     name
30 /);
31
32 use overload
33     '""' => sub { $_[0]->name },
34     '@{}' => sub { [ @{$_[0]->table->name_parts}, $_[0]->name ] },
35     fallback => 1;
36
37 =head1 METHODS
38
39 =head2 new
40
41 The constructor. Takes L</table> and L</name> key-value parameters.
42
43 =cut
44
45 sub new {
46     my $class = shift;
47
48     my $self = { @_ };
49     croak "table is required" unless ref $self->{table};
50
51     weaken $self->{table};
52
53     return bless $self, $class;
54 }
55
56 =head2 table
57
58 The L</DBIx::Class::Schema::Loader::Table> object this column belongs to.
59 Required parameter for L</new>
60
61 =head2 name
62
63 The name of the column. Required parameter for L</new>.
64
65 =cut
66
67 1;