<%method title>Redirect FleXtel Number FleXtel number <% $flextelNumber %> is diverted to <% $status->{destination} %>.

Redirect to

<%args> $new_destination => ''; <%init> use WWW::FleXtel qw(); use Storable qw(store retrieve); # Define some paramaters my $flextelNumber = '07017766554'; my $cacheTTL = 60*30; # 30 minutes my $cacheFile = '/tmp/flextelNumber.dat'; my $status = -f $cacheFile ? retrieve($cacheFile) : {}; # Define our FleXtel account my $flextel = WWW::FleXtel->new( number => $flextelNumber, pin => '????', ); # Try and redirect the number if asked to my $redirected = ''; if ($new_destination =~ /^[0-9 \+\#]+$/ && $status->{destination} !~ /^$new_destination\b/) { $redirected = $flextel->set_destination( destination => $new_destination ); } # Refresh the status data if ($redirected || !defined $status->{last_updated} || time - $status->{last_updated} > $cacheTTL) { my $destination = $flextel->get_destination; my $phonebook = $flextel->get_phonebook; # Write to the cache if we received the data back okay if (defined $destination && $destination && defined $phonebook && @{$phonebook}) { $status->{destination} = $destination; $status->{phonebook} = $phonebook; $status->{last_updated} = time; store($status, $cacheFile); } }