PageRenderTime 31ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/DDG/Spice/AlternativeTo.pm

https://github.com/tarnfeld/zeroclickinfo-spice
Perl | 65 lines | 44 code | 9 blank | 12 comment | 9 complexity | 38b8cf49791c2262c274c715b5dce24d MD5 | raw file
  1. package DDG::Spice::AlternativeTo;
  2. use DDG::Meta::Information;
  3. use DDG::Spice;
  4. triggers start => "free","opensource","commercial";
  5. triggers any => "alternative","alternatives";
  6. spice from => '([^/]+)/?(?:([^/]+)/?(?:([^/]+)|)|)';
  7. spice to => 'http://api.alternativeto.net/software/$1/?platform=$2&license=$3&count=6&callback={{callback}}';
  8. primary_example_queries => "alternative to notepad";
  9. secondary_example_queries => "alternative to photoshop for mac", "free alternative to spotify for windows";
  10. description "Find software alternatives";
  11. name "AlternativeTo";
  12. icon_url "/i/alternativeto.net.ico";
  13. source "AlternativeTo";
  14. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/AlternativeTo.pm";
  15. topics => "everyday", "programming";
  16. category => "computing";
  17. attribution github => ['https://github.com/Getty','Torsten Raudssus'],
  18. twitter => ['https://twitter.com/raudssus','Torsten Raudssus'];
  19. my %alternatives = (
  20. 'google' => 'googlecom',
  21. 'photoshop' => 'adobe-photoshop',
  22. 'yahoo' => 'yahoo-search',
  23. 'bing' => 'bingcom',
  24. );
  25. handle query_lc => sub {
  26. if (/^(?:(free|opensource|commercial))?\s*(?:alternative(?:s|)?\s*?(?:to|for)\s*?)(\b(?!for\b).*?\b)(?:\s*?for\s(.*))?$/) {
  27. my ($license, $prog, $platform) = ($1, $2, $3);
  28. $prog =~ s/\s+$//g;
  29. $prog =~ s/^\s+//g;
  30. $prog =~ s/\s+/-/g;
  31. $prog = $alternatives{$prog} if exists $alternatives{$prog};
  32. if ($license && $prog && $platform) {
  33. # license and platform specified - queries like:
  34. # -> free alternative to firefox for mac
  35. # -> opensource matlab for linux
  36. return $prog, $platform, $license;
  37. } elsif ($license && $prog) {
  38. # lincense secified only:
  39. # -> free nod32
  40. # -> opensource alternative to omnigraffle
  41. return $prog, $license;
  42. } elsif ($platform && $prog) {
  43. # platform specified:
  44. # -> TextMate for windows
  45. # -> alternative to vim for linux
  46. return $prog, $platform;
  47. } elsif($prog) {
  48. # license and platform not specified
  49. # in this case we need to match 'alternative(s) to':
  50. # -> alternative to firefox
  51. return $prog;
  52. }
  53. }
  54. return;
  55. };
  56. 1;