Mojar-Cron

 view release on metacpan or  search on metacpan

lib/Mojar/Cron/Holiday/UkGov.pm  view on Meta::CPAN

our $VERSION = 0.021;

use Mojo::UserAgent;

has agent => sub { Mojo::UserAgent->new(max_redirects => 3) };
has division => 'england-and-wales';
has url => 'https://www.gov.uk/bank-holidays.json';

sub load {
  my ($self, %param) = @_;
  require IO::Socket::SSL;

  my $tx = $self->agent->get($self->url);
  if (my $err = $tx->error) {
    $self->error(sprintf "Failed to fetch holidays (%u)\n%s",
        $err->{advice} // '0', $err->{message} // 'coded error');
    return undef;
  }

  my $loaded = $tx->res->json(sprintf '/%s/events', $self->division);
  return 0 unless @$loaded;



( run in 0.497 second using v1.01-cache-2.11-cpan-4d50c553e7e )