| 1 | package DBIx::Class::PhoneticSearch; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.01'; | |||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use constant PHONETIC_ALGORITHMS => | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | qw(DaitchMokotoff DoubleMetaphone Koeln Metaphone Phonem Phonix Soundex SoundexNara); | |||||||||
| 12 | |||||||||||
| 13 | 5 | ▶ | sub register_column { | ||||||||
|
Subroutine
register_column: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 14 | 5 | my ( $self, $column, $info, @rest ) = @_; | |||||||||
| 15 | |||||||||||
| 16 | 5 | $self->next::method( $column, $info, @rest ); | |||||||||
| 17 | |||||||||||
| 18 | 5 | ▶ | if ( my $config = $info->{phonetic_search} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 2 | ▶ | $info->{phonetic_search} = $config = { algorithm => $config } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | unless ( ref $config eq "HASH" ); | ||||||||||
| 21 | $config->{algorithm} = 'Phonix' | ||||||||||
| 22 | 2 | ▶ | unless ( grep { $config->{algorithm} eq $_ } PHONETIC_ALGORITHMS ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | $self->add_column( $column | ||||||||||
| 24 | . '_phonetic_' | ||||||||||
| 25 | 2 | . lc( $config->{algorithm} ) => | |||||||||
| 26 | { data_type => 'character varying', is_nullable => 1 } ); | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 5 | return undef; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 31 | ▶ | sub store_column { | ||||||||
|
Subroutine
store_column: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 31 | my ( $self, $name, $value, @rest ) = @_; | |||||||||
| 34 | |||||||||||
| 35 | 31 | my $info = $self->column_info($name); | |||||||||
| 36 | |||||||||||
| 37 | 31 | ▶ | if ( my $config = $info->{phonetic_search} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 10 | my $class = 'Text::Phonetic::' . $config->{algorithm}; | |||||||||
| 39 | 10 | my $column = $name . '_phonetic_' . lc( $config->{algorithm} ); | |||||||||
| 40 | 10 | $self->_require_class($class); | |||||||||
| 41 | 10 | $self->set_column( $column, $class->new->encode($value) ); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 31 | return $self->next::method( $name, $value, @rest ); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | ▶ | sub sqlt_deploy_hook { | ||||||||
|
Subroutine
sqlt_deploy_hook: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 48 | 1 | my ($self, $table, @rest) = @_; | |||||||||
| 49 | 1 | $self->maybe::next::method($table, @rest); | |||||||||
| 50 | 1 | foreach my $column($self->columns) { | |||||||||
| 51 | 5 | ▶ | next unless(my $config = $self->column_info($column)->{phonetic_search}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 2 | ▶ | next if($config->{no_indices}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 2 | my $phonetic_column = $column.'_phonetic_' . lc( $config->{algorithm} ); | |||||||||
| 54 | 2 | $table->add_index(name => 'idx_'.$phonetic_column, fields => [$phonetic_column]); | |||||||||
| 55 | 2 | $table->add_index(name => 'idx_'.$column, fields => [$column]); | |||||||||
| 56 | |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 10 | ▶ | sub _require_class { | ||||||||
|
Subroutine
_require_class: called CC=4 SCAR=14.0
| |||||||||||
| 62 | 10 | my ($self, $class) = @_; | |||||||||
| 63 | |||||||||||
| 64 | 10 | ▶ | croak "class argument missing" if !defined $class; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 10 | $class =~ s|::|/|g; | |||||||||
| 67 | 10 | $class .= ".pm"; | |||||||||
| 68 | |||||||||||
| 69 | 10 | ▶ | if ( !exists $::INC{$class} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 2 | eval { require $class }; | |||||||||
| 71 | 2 | ▶ | croak $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 10 | return; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2 | 1; | |||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||