
marvin at rectangular
Jul 30, 2008, 2:14 PM
Post #1 of 1
(385 views)
Permalink
|
|
r3681 - in trunk/perl: . lib lib/KSx lib/KinoSearch/Search t
|
|
Author: creamyg Date: 2008-07-30 14:14:52 -0700 (Wed, 30 Jul 2008) New Revision: 3681 Removed: trunk/perl/t/010-verify_args.t Modified: trunk/perl/MANIFEST trunk/perl/lib/KSx/Simple.pm trunk/perl/lib/KinoSearch.pm trunk/perl/lib/KinoSearch/Search/Query.pm Log: Eliminate Perl helper subs verify_args and kerror. Modified: trunk/perl/MANIFEST =================================================================== --- trunk/perl/MANIFEST 2008-07-30 20:30:18 UTC (rev 3680) +++ trunk/perl/MANIFEST 2008-07-30 21:14:52 UTC (rev 3681) @@ -277,7 +277,6 @@ t/001-build_invindexes.t t/002-kinosearch.t t/003-charmonizer.t -t/010-verify_args.t t/012-priority_queue.t t/013-bit_vector.t t/015-sort_external.t Modified: trunk/perl/lib/KSx/Simple.pm =================================================================== --- trunk/perl/lib/KSx/Simple.pm 2008-07-30 20:30:18 UTC (rev 3680) +++ trunk/perl/lib/KSx/Simple.pm 2008-07-30 21:14:52 UTC (rev 3681) @@ -4,8 +4,6 @@ package KSx::Simple; use KinoSearch::Util::ToolSet qw( confess - verify_args - kerror weaken reftype refaddr @@ -37,31 +35,33 @@ language => undef, # members - schema => undef, - invindex => undef, - invindexer => undef, - searcher => undef, - hits => undef, ); my %obj_cache; sub new { - my $either = shift; - confess kerror() unless verify_args( \%constructor_params, @_ ); - my $class = ref($either) || $either; - my $self = bless { %constructor_params, @_ }, $class; - - # Verify language. - my $language = lc( $self->{language} ); - croak("Invalid value for language: '$self->{language}'") + my ( $either, %args ) = @_; + my $path = delete $args{path}; + my $language = lc( delete $args{language} ); + confess("Missing required parameter 'path'") unless defined $path; + confess("Invalid language: '$language'") unless $language =~ /^(?:da|de|en|es|fi|fr|it|nl|no|pt|ru|sv)$/; - $self->{language} = $language; + my @remaining = keys %args; + confess("Invalid params: @remaining") if @remaining; + my $self = bless { + schema => undef, + invindex => undef, + invindexer => undef, + searcher => undef, + hits => undef, + language => $language, + path => $path, + }, + ref($either) || $either; # Get schema and invindex. my $schema_package = "KSx::Simple::Schema::$language"; my $schema = $self->{schema} = $schema_package->new; - confess("Missing required parameter 'path'") unless defined $self->{path}; $self->{invindex} = $schema->open( $self->{path} ); # Cache the object for later clean-up. Modified: trunk/perl/lib/KinoSearch/Search/Query.pm =================================================================== --- trunk/perl/lib/KinoSearch/Search/Query.pm 2008-07-30 20:30:18 UTC (rev 3680) +++ trunk/perl/lib/KinoSearch/Search/Query.pm 2008-07-30 21:14:52 UTC (rev 3681) @@ -28,8 +28,11 @@ END_CONSTRUCTOR_CODE_SAMPLE { "KinoSearch::Search::Query" => { - bind_methods => [qw( set_boost get_boost )], - bind_positional => [qw( _make_compiler|make_compiler )], + bind_methods => [ + qw( set_boost + get_boost + _make_compiler|make_compiler ) + ], make_constructors => ["new"], make_pod => { synopsis => $synopsis, Modified: trunk/perl/lib/KinoSearch.pm =================================================================== --- trunk/perl/lib/KinoSearch.pm 2008-07-30 20:30:18 UTC (rev 3680) +++ trunk/perl/lib/KinoSearch.pm 2008-07-30 21:14:52 UTC (rev 3681) @@ -78,9 +78,7 @@ to_kino to_perl - verify_args a_isa_b - kerror ); } @@ -126,34 +124,6 @@ } } - my $kerror; - - sub kerror {$kerror} - - # Verify that named parameters exist in a defaults hash. - sub verify_args { - my $defaults = shift; # leave the rest of @_ intact - - # Verify that args came in pairs. - if ( @_ % 2 ) { - my ( $package, $filename, $line ) = caller(1); - $kerror - = "Parameter error: odd number of args at $filename line $line\n"; - return 0; - } - - # Verify keys, ignore values. - while (@_) { - my ( $var, undef ) = ( shift, shift ); - next if exists $defaults->{$var}; - my ( $package, $filename, $line ) = caller(1); - $kerror = "Invalid parameter: '$var' at $filename line $line\n"; - return 0; - } - - return 1; - } - # a_isa_b serves the same purpose as the isa method from UNIVERSAL, only # it is called as a function rather than a method. sub a_isa_b { @@ -293,7 +263,6 @@ { package KinoSearch::Analysis::Tokenizer; - use KinoSearch::Util::ToolSet qw( confess verify_args kerror ); our %instance_vars = __PACKAGE__->init_instance_vars( # params/members @@ -301,13 +270,12 @@ ); sub new { - my $either = shift; - confess kerror() unless verify_args( \%instance_vars, @_ ); - my %args = @_; - my $self = $either->_new; - if ( $args{token_re} ) { + my ( $either, %args ) = @_; + my $token_re = delete $args{token_re}; + my $self = $either->_new(%args); + if ( $token_re ) { # Overwrite default, which has already been initialized via callback. - _cache_token_re( $self, $args{token_re} ); + _cache_token_re( $self, $token_re ); } return $self; } @@ -1017,19 +985,11 @@ { package KinoSearch::Search::Query; - use KinoSearch::Util::ToolSet qw( confess kerror verify_args ); - our %make_compiler_PARAMS = ( - searchable => undef, - boost => undef, - ); - sub make_compiler { - my $self = shift; - confess kerror() unless verify_args( \%make_compiler_PARAMS, @_ ); - my %args = @_; + my ( $self, %args ) = @_; $args{boost} = $self->get_boost unless defined $args{boost}; - return $self->_make_compiler( $args{searchable}, $args{boost} ); + return $self->_make_compiler(%args); } } Deleted: trunk/perl/t/010-verify_args.t =================================================================== --- trunk/perl/t/010-verify_args.t 2008-07-30 20:30:18 UTC (rev 3680) +++ trunk/perl/t/010-verify_args.t 2008-07-30 21:14:52 UTC (rev 3681) @@ -1,24 +0,0 @@ -use strict; -use warnings; - -use Test::More tests => 5; -use KinoSearch::Util::ToolSet qw( verify_args kerror ); - -my %defaults = ( foo => 'FOO', bar => 'BAR' ); - -sub check { - return verify_args( \%defaults, @_ ); -} - -my $dest = {}; - -my $ret = check( odd => 'number', of => ); -is( $ret, 0, "An odd number of args fails verify_args" ); -like( kerror(), qr/odd/, "verify_args sets the right error string" ); - -$ret = check( bad => 'badness' ); -is( $ret, 0, "An invalid arg chokes verify_args" ); -like( kerror(), qr/invalid/i, "verify_args sets the right error string" ); - -$ret = check( foo => 'boo' ); -is( $ret, 1, "A valid arg passes verify_args" ); _______________________________________________ kinosearch-commits mailing list kinosearch-commits [at] rectangular http://www.rectangular.com/mailman/listinfo/kinosearch-commits
|