PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/MusicBrainz/Server/Entity/URL/ASIN.pm

https://bitbucket.org/intgr/musicbrainz-server
Perl | 64 lines | 46 code | 18 blank | 0 comment | 6 complexity | 040c0afba84ed5d81f978091a0c037fe MD5 | raw file
  1. package MusicBrainz::Server::Entity::URL::ASIN;
  2. use Moose;
  3. extends 'MusicBrainz::Server::Entity::URL';
  4. with 'MusicBrainz::Server::Entity::URL::Sidebar';
  5. use DBDefs;
  6. sub pretty_name
  7. {
  8. my $self = shift;
  9. if ($self->url =~ m{^(?:https?:)?//(?:www.)?(.*?\.)([a-z]+)(?:\:[0-9]+)?/.*/([0-9B][0-9A-Z]{9})(?:[^0-9A-Z]|$)}i) {
  10. my $country = $2;
  11. $country = "US" if $country eq "com";
  12. $country =~ tr/a-z/A-Z/;
  13. return "$country: $3";
  14. }
  15. return $self->url->as_string;
  16. }
  17. sub sidebar_name { shift->pretty_name }
  18. override affiliate_url => sub {
  19. my $self = shift;
  20. my $url = super()->clone;
  21. if ($url =~ m{^(?:https?:)?//(?:.*?\.)(amazon\.([a-z\.]+))(?:\:[0-9]+)?/[^?]+$}i) {
  22. my $ass_id = DBDefs->AWS_ASSOCIATE_ID($1);
  23. return $url unless $ass_id;
  24. return URI->new("$url?tag=$ass_id");
  25. } else {
  26. return $url;
  27. }
  28. };
  29. sub url_is_scheme_independent { 1 }
  30. __PACKAGE__->meta->make_immutable;
  31. no Moose;
  32. 1;
  33. =head1 COPYRIGHT
  34. Copyright (C) 2010 MetaBrainz Foundation
  35. This program is free software; you can redistribute it and/or modify
  36. it under the terms of the GNU General Public License as published by
  37. the Free Software Foundation; either version 2 of the License, or
  38. (at your option) any later version.
  39. This program is distributed in the hope that it will be useful,
  40. but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  42. GNU General Public License for more details.
  43. You should have received a copy of the GNU General Public License
  44. along with this program; if not, write to the Free Software
  45. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46. =cut