WWW::Mixi::Scraper::Utils - internal utilities


WWW-Mixi-Scraper documentation Contained in the WWW-Mixi-Scraper distribution.

Index


Code Index:

NAME

Top

WWW::Mixi::Scraper::Utils - internal utilities

DESCRIPTION

Top

Used internally.

AUTHOR

Top

Kenichi Ishigaki, <ishigaki at cpan.org>

COPYRIGHT AND LICENSE

Top


WWW-Mixi-Scraper documentation Contained in the WWW-Mixi-Scraper distribution.

package WWW::Mixi::Scraper::Utils;

use strict;
use warnings;
use base qw/Exporter/;
use URI;
use URI::QueryParam;

our @EXPORT_OK = qw( _force_arrayref _uri _datetime );

sub _force_arrayref {
  my $thingy = shift;

  return []        if !defined $thingy || $thingy eq '';
  return [$thingy] if ref $thingy ne 'ARRAY';
  return $thingy;
}

sub _datetime {
  my $date = shift;

  unless ( defined $date ) {
    warn "datetime is not defined"; return;
  }

  my $time;
  if ( $date =~ s/\s*(\d+:\d+(?::\d+)?)\s*$// ) {
    $time = $1;
  }

  $date =~ s/\D/\-/g;
  $date =~ s/\-+$//;

  return $time ? "$date $time" : $date; # should be DateTime object?
}

sub _uri {
  my $uri = URI->new(shift);
  $uri->authority('mixi.jp') unless $uri->authority;
  $uri->scheme('http')       unless $uri->scheme;
  return $uri;
}

1;

__END__