Geo-Postcodes

 view release on metacpan or  search on metacpan

lib/Geo/Postcodes/Update.pm  view on Meta::CPAN

package Geo::Postcodes::Update;

#################################################################################
#                                                                               #
#           This file is written by Arne Sommer - perl@bbop.org                 #
#                                                                               #
#################################################################################

use strict;
use warnings;

use LWP::Simple (); 

our $VERSION = '0.311';

#################################################################################

sub update
{
  my $module_name   = shift;
  my $file_name     = shift;
  my $full_url      = shift; # Can be 'undef'
  my $procedure     = shift;
  my $update        = shift; # Do not update the module, but show the resulting perl code.

  $module_name = "$module_name.pm" unless $module_name =~ /\.pm$/;
 
  unless (-e $module_name)
  {
    if (-e "lib/Geo/Postcodes/")
    {
      chdir("lib/Geo/Postcodes/");
    }
    elsif (-e "../lib/Geo/Postcodes/")
    {
      chdir("../lib/Geo/Postcodes/");
    }
  }

  die("Unable to find '$module_name'") unless -e $module_name;

  my $in = "../../../misc/$file_name";

  my $downloaded = 0;

  unless (-e $in)
  {
    print "The file 'misc/$file_name' does not exist.\n";
    $downloaded = _download_it($full_url, $in) if $full_url;
  }

  die "Unable to open the file 'misc/$file_name'.\n - Unable to update the module.\n" unless -e $in;

  unless (_update_module($module_name, $in, $procedure, $update))
  {
    unless ($downloaded)
    {
      $downloaded = _download_it($full_url, $in) if $full_url;

      _update_module($module_name, $in, $procedure, $update) if $downloaded;
    }
  }
}

################################################################################

sub _download_it
{
  my $full_url = shift;
  my $in       = shift;

  if (_ask("Do you want to download '$full_url'"))
  {
    if (-e $in)
    {
      rename($in, $in . "." . time());
    }



( run in 0.794 second using v1.01-cache-2.11-cpan-2398b32b56e )