Business-Cart-Generic
view release on metacpan or search on metacpan
lib/Business/Cart/Generic/Database/Import.pm view on Meta::CPAN
package Business::Cart::Generic::Database::Import;
use strict;
use warnings;
use CGI;
use FindBin;
use Business::Cart::Generic::Database;
use IO::File;
use Moose;
use Perl6::Slurp;
use Text::CSV_XS;
use Text::Xslate;
use Try::Tiny;
use WWW::Scraper::Wikipedia::ISO3166::Database;
extends 'Business::Cart::Generic::Database::Base';
has country_map =>
(
default => sub{return build_country_map()},
is => 'rw',
isa => 'HashRef',
required => 0,
);
use namespace::autoclean;
our $VERSION = '0.85';
# -----------------------------------------------
sub BUILD
{
my($self) = @_;
$self -> db
(
Business::Cart::Generic::Database -> new
(
online => 0,
query => CGI -> new,
)
);
} # End of BUILD.
# -----------------------------------------------
# Warning: This is a function. Hence no $self.
sub build_country_map
{
my($country) = WWW::Scraper::Wikipedia::ISO3166::Database -> new -> read_countries_table;
my(%code2country);
for my $id (keys %$country)
{
$code2country{$$country{$id}{code2} } = {%{$$country{$id} } };
}
return \%code2country;
} # End of build_country_map.
# -----------------------------------------------
sub clean_all_data
{
my($self) = @_;
$self -> clean_currency_data;
$self -> clean_language_data;
$self -> clean_order_statuses_data;
} # End of clean_all_data.
# -----------------------------------------------
sub clean_currency_data
{
my($self) = @_;
my($input_path) = "$FindBin::Bin/../data/raw.currencies.txt";
my(@original_data) = slurp($input_path, {chomp => 1});
my(@field);
my($line);
( run in 0.771 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )