File Coverage

blib/lib/SQL/Translator/Schema/IndexField.pm
Criterion Covered Total %
statement 7 7 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 10 100.0


line stmt bran cond sub pod time code
1             package SQL::Translator::Schema::IndexField;
2              
3             =pod
4              
5             =head1 NAME
6              
7             SQL::Translator::Schema::IndexField - SQL::Translator index field object
8              
9             =head1 DESCRIPTION
10              
11             C is the index field object.
12              
13             Different databases allow for different options on index fields. Those are supported through here
14              
15             =head1 METHODS
16              
17             =cut
18              
19 76     76   531 use Moo;
  76         176  
  76         566  
20              
21             extends 'SQL::Translator::Schema::Object';
22              
23 76     76   50736 use overload '""' => sub { shift->name };
  76     341   229  
  76         1190  
  341         3085  
24              
25             =head2 new
26              
27             Object constructor.
28              
29             my $schema = SQL::Translator::Schema::IndexField->new;
30              
31             =head2 name
32              
33             The name of the index. The object stringifies to this. In addition, you can simply pass
34             a string to the constructor to only set this attribute.
35              
36             =head2 extra
37              
38             All options for the field are stored under the extra hash. The constructor will collect
39             them for you if passed in straight. In addition, an accessor is provided for all supported options
40              
41             Currently supported options:
42              
43             =over 4
44              
45             =item prefix_length
46              
47             Supported by MySQL. Indicates that only N characters of the column are indexed.
48              
49             =back
50              
51             =cut
52              
53             around BUILDARGS => sub {
54             my ($orig, $self, @args) = @_;
55             if (@args == 1 && !ref $args[0]) {
56             @args = (name => $args[0]);
57             }
58              
59             # there are some weird pathological cases where we get an object passed in rather than a
60             # hashref. We'll just clone it
61             if (ref $args[0] eq $self) {
62             return { %{ $args[0] } };
63             }
64             my $args = $self->$orig(@args);
65             my $extra = delete $args->{extra} || {};
66             my $name = delete $args->{name};
67             return {
68             name => $name,
69             extra => { %$extra, %$args }
70             };
71             };
72              
73             has name => (
74             is => 'rw',
75             required => 1,
76             );
77              
78             has extra => (
79             is => 'rw',
80             default => sub { {} },
81             );
82              
83             =pod
84              
85             =head1 AUTHOR
86              
87             Veesh Goldman Eveesh@cpan.orgE.
88              
89             =cut
90              
91             9007