File: IndexField.pm

package info (click to toggle)
libsql-translator-perl 1.66-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,680 kB
  • sloc: perl: 67,870; sql: 4,150; xml: 258; makefile: 14
file content (91 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download
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
package SQL::Translator::Schema::IndexField;

=pod

=head1 NAME

SQL::Translator::Schema::IndexField - SQL::Translator index field object

=head1 DESCRIPTION

C<SQL::Translator::Schema::IndexField> is the index field object.

Different databases allow for different options on index fields. Those are supported through here

=head1 METHODS

=cut

use Moo;

extends 'SQL::Translator::Schema::Object';

use overload '""' => sub { shift->name };

=head2 new

Object constructor.

  my $schema = SQL::Translator::Schema::IndexField->new;

=head2 name

The name of the index. The object stringifies to this. In addition, you can simply pass
a string to the constructor to only set this attribute.

=head2 extra

All options for the field are stored under the extra hash. The constructor will collect
them for you if passed in straight. In addition, an accessor is provided for all supported options

Currently supported options:

=over 4

=item prefix_length

Supported by MySQL. Indicates that only N characters of the column are indexed.

=back

=cut

around BUILDARGS => sub {
  my ($orig, $self, @args) = @_;
  if (@args == 1 && !ref $args[0]) {
    @args = (name => $args[0]);
  }

# there are some weird pathological cases where we get an object passed in rather than a
# hashref. We'll just clone it
  if (ref $args[0] eq $self) {
    return { %{ $args[0] } };
  }
  my $args  = $self->$orig(@args);
  my $extra = delete $args->{extra} || {};
  my $name  = delete $args->{name};
  return {
    name  => $name,
    extra => { %$extra, %$args }
  };
};

has name => (
  is       => 'rw',
  required => 1,
);

has extra => (
  is      => 'rw',
  default => sub { {} },
);

=pod

=head1 AUTHOR

Veesh Goldman E<lt>veesh@cpan.orgE<gt>.

=cut

9007