Skip to content

Commit

Permalink
Fix the previous fix
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Nov 18, 2024
1 parent c116019 commit 22f7023
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 45 deletions.
14 changes: 14 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.9] - 2024-11-18

### Fixed

- Fix the previous fix

## [0.1.8] - 2024-11-18

### Fixed

- Worked out why we needed the 'package' statement

- Fixed the problem and removed the statement

## [0.1.7] - 2024-08-30

### Fixed
Expand Down
89 changes: 44 additions & 45 deletions lib/Amazon/Sites.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ use Feature::Compat::Class;
use feature 'signatures';
no warnings 'experimental::signatures';

our $VERSION = '0.1.7';
our $VERSION = '0.1.9';

class Amazon::Sites {
class Amazon::Sites;

use Amazon::Site ();
use Amazon::Site ();

field $include :param = [];
field $exclude :param = [];
field $assoc_codes :param = {};
field %sites = _init_sites($assoc_codes, $include, $exclude);
field $include :param = [];
field $exclude :param = [];
field $assoc_codes :param = {};
field %sites = _init_sites($assoc_codes, $include, $exclude);

ADJUST {
if (@$include and @$exclude) {
die "You can't specify both include and exclude";
}
ADJUST {
if (@$include and @$exclude) {
die "You can't specify both include and exclude";
}
}

=head1 METHODS
Expand Down Expand Up @@ -81,63 +81,63 @@ L<Amazon::Site> objects.
=cut

method sites_hash { return %sites }
method sites_hash { return %sites }

=head2 site($code)
Given a two-letter country code, returns the corresponding L<Amazon::Site> object.
=cut

method site ($code) { return $sites{$code} }
method site ($code) { return $sites{$code} }

=head2 sites
Returns a list of L<Amazon::Site> objects, sorted by the sort order.
=cut

method sites {
my @sites = sort {
$a->sort <=> $b->sort;
} values %sites;
method sites {
my @sites = sort {
$a->sort <=> $b->sort;
} values %sites;

return @sites;
}
return @sites;
}

sub _init_sites($assoc_codes, $include, $exclude) {
my %sites;
my @cols = qw[code country tldn currency sort];
sub _init_sites($assoc_codes, $include, $exclude) {
my %sites;
my @cols = qw[code country tldn currency sort];

my $where = tell main::DATA;
my $where = tell DATA;

while (<main::DATA>) {
chomp;
my %site;
@site{@cols} = split /\t/;
while (<DATA>) {
chomp;
my %site;
@site{@cols} = split /\t/;

next if @$include and not grep { $site{code} eq $_ } @$include;
next if @$exclude and grep { $site{code} eq $_ } @$exclude;
next if @$include and not grep { $site{code} eq $_ } @$include;
next if @$exclude and grep { $site{code} eq $_ } @$exclude;

$site{assoc_code} = $assoc_codes->{$site{code}} if $assoc_codes->{$site{code}};
$site{assoc_code} = $assoc_codes->{$site{code}} if $assoc_codes->{$site{code}};

$sites{$site{code}} = Amazon::Site->new(%site);
}
$sites{$site{code}} = Amazon::Site->new(%site);
}

seek main::DATA, $where, 0;
seek DATA, $where, 0;

return %sites;
}
return %sites;
}

=head2 codes
Returns a list of the two-letter country codes, sorted by the sort order.
=cut

method codes {
return sort keys %sites;
}
method codes {
return sort keys %sites;
}

=head2 asin_urls
Expand All @@ -146,14 +146,13 @@ codes and the values are the corresponding ASIN URLs.
=cut

method asin_urls ($asin) {
my %urls;
for my $site ($self->sites) {
$urls{$site->code} = $site->asin_url($asin);
}

return %urls;
method asin_urls ($asin) {
my %urls;
for my $site ($self->sites) {
$urls{$site->code} = $site->asin_url($asin);
}

return %urls;
}

1;
Expand Down

0 comments on commit 22f7023

Please sign in to comment.