| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Amazon::Site - A class to represent an Amazon site | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | use Amazon::Site; | ||
| 8 | |||
| 9 | my $site = Amazon::Site->new( | ||
| 10 | code => 'UK', | ||
| 11 | country => 'United Kingdom', | ||
| 12 | tldn => 'co.uk', | ||
| 13 | currency => 'GBP', | ||
| 14 | sort => 1, | ||
| 15 | ); | ||
| 16 | |||
| 17 | say $site->tldn; # co.uk | ||
| 18 | say $site->domain; # amazon.co.uk | ||
| 19 | say $site->asin_url('XXXXXXX'); # https://amazon.co.uk/dp/XXXXXXX | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | |||
| 26 | 0 | ▶ | use Feature::Compat::Class; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 27 | |||
| 28 | use feature 'signatures'; | ||
| 29 | no warnings 'experimental::signatures'; | ||
| 30 | |||
| 31 | class Amazon::Site; | ||
| 32 | |||
| 33 | our $VERSION = '0.1.10'; | ||
| 34 | |||
| 35 | field $code :param; | ||
| 36 | field $country :param; | ||
| 37 | field $tldn :param; | ||
| 38 | field $currency :param; | ||
| 39 | field $sort :param; | ||
| 40 | field $assoc_code :param = ''; | ||
| 41 | |||
| 42 | =head1 METHODS | ||
| 43 | |||
| 44 | =head2 new | ||
| 45 | |||
| 46 | Creates a new Amazon::Site object. | ||
| 47 | |||
| 48 | =head3 Parameters | ||
| 49 | |||
| 50 | =over 4 | ||
| 51 | |||
| 52 | =item code | ||
| 53 | |||
| 54 | The two-letter country code. | ||
| 55 | |||
| 56 | =item country | ||
| 57 | |||
| 58 | The country name. | ||
| 59 | |||
| 60 | =item tldn | ||
| 61 | |||
| 62 | The top-level domain name. | ||
| 63 | |||
| 64 | =item currency | ||
| 65 | |||
| 66 | The currency code. | ||
| 67 | |||
| 68 | =item sort | ||
| 69 | |||
| 70 | The sort order. Used by Amazon::Sites to sort the sites. | ||
| 71 | |||
| 72 | =item assoc_code | ||
| 73 | |||
| 74 | The optional Amazon Associate code for this site. | ||
| 75 | |||
| 76 | =back | ||
| 77 | |||
| 78 | =head2 code | ||
| 79 | |||
| 80 | Returns the two-letter country code. | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | method code { return $code } | ||
| 85 | |||
| 86 | =head2 country | ||
| 87 | |||
| 88 | Returns the country name. | ||
| 89 | |||
| 90 | =cut | ||
| 91 | method country { return $country } | ||
| 92 | |||
| 93 | =head2 tldn | ||
| 94 | |||
| 95 | Returns the top-level domain name. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | method tldn { return $tldn } | ||
| 100 | |||
| 101 | =head2 domain | ||
| 102 | |||
| 103 | Return the whole domain name. | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | method domain { return "amazon.$tldn" } | ||
| 108 | |||
| 109 | =head2 currency | ||
| 110 | |||
| 111 | Returns the currency code. | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | method currency { return $currency } | ||
| 116 | |||
| 117 | =head2 sort | ||
| 118 | |||
| 119 | Returns the sort order. | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | method sort { return $sort } | ||
| 124 | |||
| 125 | =head2 assoc_code | ||
| 126 | |||
| 127 | Returns the Amazon Associate code for this site. | ||
| 128 | |||
| 129 | =cut | ||
| 130 | |||
| 131 | method assoc_code { return $assoc_code } | ||
| 132 | |||
| 133 | =head2 asin_url($asin) | ||
| 134 | |||
| 135 | Returns the URL for the ASIN on this site. | ||
| 136 | |||
| 137 | If you've defined an associate code for this site, it will be included in the URL. | ||
| 138 | |||
| 139 | =cut | ||
| 140 | |||
| 141 | method asin_url($asin) { | ||
| 142 | my $url = 'https://' . $self->domain . "/dp/$asin"; | ||
| 143 | $url .= "?tag=$assoc_code" if $assoc_code; | ||
| 144 | |||
| 145 | return $url; | ||
| 146 | } | ||
| 147 | |||
| 148 | =head1 COPYRIGHT | ||
| 149 | |||
| 150 | Copyright 2024, Dave Cross. All rights reserved. | ||
| 151 | |||
| 152 | =head1 LICENCE | ||
| 153 | |||
| 154 | This program is free software; you can redistribute it and/or modify it under | ||
| 155 | the terms of either: | ||
| 156 | |||
| 157 | =over 4 | ||
| 158 | |||
| 159 | =item * the GNU General Public License as published by the Free Software | ||
| 160 | Foundation; either version 1, or (at your option) any later version, or | ||
| 161 | |||
| 162 | =item * the Artistic License version 2.0. | ||
| 163 | |||
| 164 | =back | ||
| 165 | |||
| 166 | =cut | ||
| 167 | |||
| 168 | 1; | ||