PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/CodeSearch.pm

http://github.com/duckduckgo/zeroclickinfo-spice
Perl | 27 lines | 16 code | 10 blank | 1 comment | 1 complexity | cd5d6eb99efe8e04d151843839cf2d07 MD5 | raw file
Possible License(s): Apache-2.0
  1. package DDG::Spice::CodeSearch;
  2. # ABSTRACT: Code search
  3. use strict;
  4. use DDG::Spice;
  5. triggers startend => "code", "example";
  6. spice to => 'https://searchcode.com/api/jsonp_codesearch_I/?q=$1&callback={{callback}}';
  7. my $languages = join "|", share('languages.txt')->slurp;
  8. handle remainder => sub {
  9. if ($_ =~ m/\b($languages)\b/x) {
  10. my $match = $1;
  11. $match =~ s/\+/\\+/g;
  12. s/\s*$match\s*//i;
  13. return "lang:".$match." ".$_;
  14. }
  15. return;
  16. };
  17. 1;