Simplify key search
|
1 |
package DBIx::Custom::KeyInfo; |
2 | ||
3 |
use strict; |
|
4 |
use warnings; |
|
5 | ||
6 |
use base 'Object::Simple'; |
|
7 | ||
8 |
__PACKAGE__->attr([qw/column id table pos/]); |
|
9 | ||
10 |
sub new { |
|
11 |
my $self = shift; |
|
12 |
|
|
13 |
if (@_ == 1) { |
|
14 |
$self = $self->SUPER::new; |
|
15 |
$self->parse($_[0]); |
|
16 |
return $self; |
|
17 |
} |
|
18 |
|
|
19 |
return $self->SUPER::new(@_); |
|
20 |
} |
|
21 | ||
22 |
sub parse { |
|
23 |
my ($self, $key) = @_; |
|
24 |
|
|
25 |
# Parse |
|
many change
|
26 |
($key || '') =~ /^(?:(.+?)\.)?(.+?)(?:#(.+))?$/; |
fix tests
|
27 |
$self->table($1 || ''); |
28 |
$self->column($2 || ''); |
|
29 |
$self->id($3 || ''); |
|
Simplify key search
|
30 |
|
31 |
return $self; |
|
32 |
} |
|
33 | ||
34 |
1; |
|
35 | ||
36 |
=head1 NAME |
|
37 | ||
38 |
DBIx::Custom::KeyInfo - DBIx::Custom column |
|
39 | ||
40 |
=head1 SYNOPSIS |
|
41 |
|
|
42 |
# New |
|
43 |
my $key_info = DBIx::Custom::KeyInfo->new; |
|
44 |
|
|
45 |
# Parse |
|
46 |
$key_info->parse('books.author@IDxxx'); |
|
47 |
|
|
48 |
# Attributes |
|
49 |
my $name = $key_info->name; |
|
50 |
my $table = $key_info->table; |
|
51 |
my $id = $key_info->id; |
|
52 | ||
53 |
=head1 ATTRIBUTES |
|
54 | ||
55 |
=head2 id |
|
56 | ||
57 |
$key_info = $key_info->id($id); |
|
58 |
$id = $key_info->id |
|
59 | ||
60 |
=head2 name |
|
61 | ||
62 |
$key_info = $key_info->name($name); |
|
63 |
$name = $key_info->name |
|
64 | ||
65 |
=head2 table |
|
66 | ||
67 |
$key_info = $key_info->table($table); |
|
68 |
$table = $key_info->table |
|
69 | ||
70 |
=head1 METHODS |
|
71 | ||
72 |
=head2 new |
|
73 | ||
74 |
$key_info = DBIx::Custom::KeyInfo->new(\%args); |
|
75 |
$key_info = DBIx::Custom::KeyInfo->new(%args); |
|
76 |
$key_info = DBIx::Custom::KeyInfo->new('books.author@where'); |
|
77 | ||
78 |
=head2 parse |
|
79 | ||
80 |
$key_info->parse('books.author@IDxxx'); |
|
81 | ||
82 |
=cut |