File: | blib/lib/MySQL/Util/Lite/Column.pm |
Coverage: | 48.9% |
line | stmt | bran | cond | sub | code |
---|---|---|---|---|---|
1 | package MySQL::Util::Lite::Column; | ||||
2 | |||||
3 | our $VERSION = '0.01'; | ||||
4 | |||||
5 | 1 1 1 | use Modern::Perl; | |||
6 | 1 1 1 | use Moose; | |||
7 | 1 1 1 | use namespace::autoclean; | |||
8 | 1 1 1 | use Method::Signatures; | |||
9 | 1 1 1 | use Data::Printer alias => 'pdump'; | |||
10 | |||||
11 | has name => ( | ||||
12 | is => 'ro', | ||||
13 | isa => 'Str', | ||||
14 | required => 1, | ||||
15 | ); | ||||
16 | |||||
17 | has table_name => ( | ||||
18 | is => 'ro', | ||||
19 | isa => 'Str', | ||||
20 | required => 1, | ||||
21 | ); | ||||
22 | |||||
23 | has schema_name => ( | ||||
24 | is => 'ro', | ||||
25 | isa => 'Str', | ||||
26 | required => 1, | ||||
27 | ); | ||||
28 | |||||
29 | has key => ( | ||||
30 | is => 'ro', | ||||
31 | isa => 'Str|Undef', | ||||
32 | ); | ||||
33 | |||||
34 | has default => ( | ||||
35 | is => 'ro', | ||||
36 | isa => 'Str|Undef', | ||||
37 | ); | ||||
38 | |||||
39 | has type => ( | ||||
40 | is => 'ro', | ||||
41 | isa => 'Str', | ||||
42 | required => 1, | ||||
43 | ); | ||||
44 | |||||
45 | has is_null => ( | ||||
46 | is => 'ro', | ||||
47 | isa => 'Bool', | ||||
48 | required => 1, | ||||
49 | ); | ||||
50 | |||||
51 | has is_autoinc => ( | ||||
52 | is => 'ro', | ||||
53 | isa => 'Bool', | ||||
54 | default => 0, | ||||
55 | ); | ||||
56 | |||||
57 | 1 0 0 | method get_moose_type { | |||
58 | |||||
59 | 0 | my $str; | |||
60 | 0 | my $type = $self->type; | |||
61 | |||||
62 | 0 | if ( $type =~ /varchar/i ) { | |||
63 | 0 | $str = 'Str|HashRef'; | |||
64 | } | ||||
65 | elsif ( $type =~ /timestamp/i ) { | ||||
66 | 0 | $str = 'Str|HashRef'; | |||
67 | } | ||||
68 | elsif ( $type =~ /enum/i ) { | ||||
69 | 0 | $str = 'Str|HashRef'; | |||
70 | } | ||||
71 | else { | ||||
72 | 0 | $str = 'Num|HashRef'; | |||
73 | } | ||||
74 | |||||
75 | 0 | if ( $self->is_null ) { | |||
76 | 0 | $str .= '|Undef'; | |||
77 | } | ||||
78 | |||||
79 | 0 | return $str; | |||
80 | } | ||||
81 | |||||
82 | 1; |