Changeset 2563


Ignore:
Timestamp:
03/02/10 00:35:33 (2 years ago)
Author:
karpet
Message:

add translate_to() method

Location:
Search-Query/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • Search-Query/trunk/Changes

    r2555 r2563  
    4040          expand to all defined if fields if 'default_field' is not 
    4141          specified. 
     42        * add translate_to() method to base Dialect class. 
    4243 
  • Search-Query/trunk/MANIFEST

    r2559 r2563  
    2020t/04-sql.t 
    2121t/05-swish.t 
     22t/06-translate.t 
    2223t/pod-coverage.t 
    2324t/pod.t 
  • Search-Query/trunk/lib/Search/Query/Dialect.pm

    r2562 r2563  
    144144} 
    145145 
     146=head2 translate_to( I<dialect> ) 
     147 
     148Translate from one Dialect to another. Returns an object 
     149blessed into the I<dialect> class. 
     150 
     151=cut 
     152 
     153sub translate_to { 
     154    my $self        = shift; 
     155    my $dialect     = shift or croak "Dialect required"; 
     156    my $query_class = Search::Query->get_dialect($dialect); 
     157    my $new_dialect = bless( Clone::clone($self), $query_class ); 
     158    my $code        = sub { 
     159        my ( $clause, $tree, $sub, $prefix ) = @_; 
     160        if ( $clause->is_tree ) { 
     161            bless( $clause->value, $query_class ); 
     162            $clause->value->walk($sub); 
     163        } 
     164    }; 
     165    $new_dialect->walk($code); 
     166    return $new_dialect; 
     167} 
     168 
    146169=head2 add_or_clause( I<clause> ) 
    147170 
Note: See TracChangeset for help on using the changeset viewer.