This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package DDG::Meta::ShareDir; | ||
|
||
use strict; | ||
use warnings; | ||
use Carp; | ||
use Module::Data; | ||
use Path::Class; | ||
use File::ShareDir ':ALL'; | ||
|
||
my %applied; | ||
|
||
sub apply_keywords { | ||
my ( $class, $target ) = @_; | ||
|
||
return if exists $applied{$target}; | ||
$applied{$target} = undef; | ||
|
||
my @parts = split('::',$target); | ||
shift @parts; | ||
my $share_path = join('/',map { s/([a-z])([A-Z])/$1_$2/; lc; } @parts); | ||
|
||
my $moddata = Module::Data->new($target); | ||
|
||
my $share; | ||
|
||
if ( -e $moddata->root->parent->subdir('lib') ) { | ||
return unless -e $moddata->root->parent->subdir('share'); | ||
$share = dir($moddata->root->parent->subdir('share'),$share_path); | ||
} else { | ||
$share = dir(module_dir($target)); | ||
} | ||
|
||
{ | ||
no strict "refs"; | ||
|
||
*{"${target}::module_share_dir"} = sub { dir('share',$share_path) }; | ||
*{"${target}::share"} = sub { $share }; | ||
} | ||
|
||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package DDG::Meta::ZeroClickInfoSpice; | ||
|
||
use strict; | ||
use warnings; | ||
use Carp; | ||
use DDG::ZeroClickInfo::Spice; | ||
|
||
sub zeroclickinfospice_attributes {qw( | ||
js | ||
js_include | ||
is_cached | ||
)} | ||
|
||
sub check_zeroclickinfospice_key { | ||
my $key = shift; | ||
if (grep { $key eq $_ } zeroclickinfospice_attributes) { | ||
return $key; | ||
} else { | ||
croak $key." is not supported on DDG::ZeroClickInfo::Spice"; | ||
} | ||
} | ||
|
||
my %applied; | ||
|
||
sub apply_keywords { | ||
my ( $class, $target ) = @_; | ||
|
||
return if exists $applied{$target}; | ||
$applied{$target} = undef; | ||
|
||
my @parts = split('::',$target); | ||
shift @parts; | ||
shift @parts; | ||
my $answer_type = lc(join(' ',@parts)); | ||
|
||
{ | ||
my %zcispice_params = (); | ||
no strict "refs"; | ||
|
||
*{"${target}::spice_new"} = sub { | ||
shift; | ||
DDG::ZeroClickInfo::Spice->new(%zcispice_params, ref $_[0] eq 'HASH' ? %{$_[0]} : @_) | ||
}; | ||
*{"${target}::spice"} = sub { | ||
if (ref $_[0] eq 'HASH') { | ||
for (keys %{$_[0]}) { | ||
$zcispice_params{check_zeroclickinfospice_key($_)} = $_[0]->{$_}; | ||
} | ||
} else { | ||
while (@_) { | ||
my $key = shift; | ||
my $value = shift; | ||
$zcispice_params{check_zeroclickinfospice_key($key)} = $value; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
use FindBin qw($Bin); | ||
use lib "$Bin/lib"; | ||
|
||
use DDGTest::Spice::Words; | ||
use DDGTest::Spice::Regexp; | ||
|
||
my $spice = DDGTest::Spice::Words->new( block => undef ); | ||
|
||
isa_ok($spice,'DDGTest::Spice::Words'); | ||
|
||
is_deeply(DDGTest::Spice::Words->get_triggers,{ | ||
startend => [ "foo", "foofoo", "afoo", "afoofoo" ], | ||
start => [ "bar", "baz", "buu", "abar", "abaz" ], | ||
},'Checking resulting get_triggers of DDGTest::Spice::Words'); | ||
|
||
my $re = DDGTest::Spice::Regexp->new( block => undef ); | ||
|
||
isa_ok($re,'DDGTest::Spice::Regexp'); | ||
|
||
is_deeply(DDGTest::Spice::Regexp->get_triggers,{ | ||
query_raw => [qr/aregexp (.*)/i, qr/bregexp (.*) (.*)/i, qr/cregexp (.*)/i] | ||
},'Checking resulting get_triggers of DDGTest::Spice::Regexp',); | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package DDGTest::Spice::Regexp; | ||
|
||
use DDG::Spice; | ||
|
||
triggers qr/aregexp (.*)/i; | ||
|
||
triggers qr/bregexp (.*) (.*)/i, qr/cregexp (.*)/i; | ||
|
||
handle matches => sub { return join('|',@_) }; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package DDGTest::Spice::Words; | ||
|
||
use DDG::Spice; | ||
|
||
triggers startend => 'foo'; | ||
|
||
triggers start => 'bar', 'baz'; | ||
triggers start => 'buu'; | ||
|
||
triggers startend => 'foofoo'; | ||
|
||
triggers sub { | ||
start => [qw(abar abaz)], | ||
}; | ||
|
||
triggers startend => sub { 'afoo', 'afoofoo' }; | ||
|
||
handle remainder => sub { shift; }; | ||
|
||
1; |