PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/DDG/Spice/AlternativeTo.pm

http://github.com/duckduckgo/zeroclickinfo-spice
Perl | 43 lines | 33 code | 9 blank | 1 comment | 6 complexity | 0407cb77676e35c339f7d930b299b6c4 MD5 | raw file
Possible License(s): Apache-2.0
  1. package DDG::Spice::AlternativeTo;
  2. # ABSTRACT: Alternative software for some other software
  3. use strict;
  4. use DDG::Spice;
  5. triggers start => "free","opensource","commercial";
  6. triggers any => "alternative","alternatives","alternativeto";
  7. spice from => '([^/]+)/(.*?)/([^/]*)';
  8. spice to => 'http://api.alternativeto.net/software/$1/?platform=$2&license=$3&count=12&callback={{callback}}&key={{ENV{DDG_SPICE_ALTERNATIVETO_APIKEY}}}';
  9. spice content_type_javascript => 1;
  10. my %alternatives = (
  11. 'google' => 'googlecom',
  12. 'photoshop' => 'adobe-photoshop',
  13. 'yahoo' => 'yahoo-search',
  14. 'bing' => 'bingcom',
  15. 'mac-os-x' => 'mac-os'
  16. );
  17. handle query_lc => sub {
  18. if (/^(?:(free|open\s?source|commercial))?\s*(?:alternative(?:s|)?\s*?(?:to|for)\s*?)(\b(?!for\b).*?\b)(?:\s*?for\s(.*))?$/) {
  19. my $license = $1 || "";
  20. my $prog = $2 || "";
  21. my $platform = $3 || "";
  22. $license =~ s/\s+//;
  23. $prog =~ s/\s+$//g;
  24. $prog =~ s/^\s+//g;
  25. $prog =~ s/\s+/-/g;
  26. $prog = $alternatives{$prog} if exists $alternatives{$prog};
  27. if($platform) {
  28. return $prog, $platform, $license;
  29. }
  30. return $prog, "all", $license;
  31. }
  32. return;
  33. };
  34. 1;