PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/SearchCode.pm

https://github.com/aembleton/zeroclickinfo-spice
Perl | 43 lines | 27 code | 9 blank | 7 comment | 3 complexity | dc34639d2db9516baaf15aba6cf967e9 MD5 | raw file
  1. package DDG::Spice::SearchCode;
  2. use DDG::Spice;
  3. name "SearchCode";
  4. description "search through APIs and open source repositories";
  5. source "Search[code]";
  6. attribution twitter => ["https://twitter.com/boyter", "boyter"],
  7. github => ["https://github.com/boyter", "Ben Boyter"];
  8. primary_example_queries "underscore.js bind";
  9. secondary_example_queries "php print_r";
  10. category "reference";
  11. topics "programming";
  12. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/SearchCode.pm";
  13. icon_url "/i/searchco.de.ico";
  14. status "enabled";
  15. triggers startend => "apache2","apache","apple ios","ios","brainfuck","clojure","cobol","emacs","fossil","ftp code","git","hello world","hresult","http code","java","jquery","linux command","linux kernel error","kernel error","mercurial","hg","mysql error","mysql function","nt status","osx","perl","perl5","perl5 var","perl var","php","python","smarty","sql server function","sql server","svn","underscore.js","underscore","vb6","win32 error","windows command";
  16. spice to => 'http://searchco.de/api/jsonp_search_IV/?q=$1&callback={{callback}}';
  17. # list of trigger words
  18. my $words = 'apache2\s*directive|apache|apache2|apple\s*ios|ios|brainfuck|clojure|cobol|emacs|fossil|ftp\s*code|git|hello\s*world|hresult|http\s*code|java|jquery|linux\s*command|linux\s*kernel\s*error|mercurial|hg|mysql\s*error|mysql\s*function|nt\s*status|osx|perl|perl5|perl5\s*var|perl\s*var|php|python|smarty|snippet|sql\s*server\s*function|sql\*server|svn|underscore\.js|underscore|vb6|win32\s*error|windows\s*command';
  19. handle query_raw => sub {
  20. # don't trigger on:
  21. # app (for Quixey)
  22. # code/example (for CodeSearch)
  23. # jobs (for Github jobs)
  24. return if m/(^|\s+)(app|code|example|jobs)(\s+|$)/ig;
  25. # make sure there is more to the
  26. # query besides the trigger itself
  27. if (m/$words/i){
  28. my $query = $_;
  29. s/$words//ig;
  30. return $query if length $_ > 1;
  31. }
  32. return;
  33. };
  34. 1;