Skip to content

Commit

Permalink
removed some redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
sshaw committed Dec 3, 2011
1 parent 8cb960c commit 7014447
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
32 changes: 13 additions & 19 deletions lib/URI/fasp.pm
Expand Up @@ -10,25 +10,32 @@ use URI::QueryParam;

our $VERSION = '0.01';

{
no strict 'refs';
for my $attr (qw|bwcap policy httpport targetrate|) {
*$attr = sub {
shift->query_param($attr, @_);
}
}
}

sub _init
{
my $class = shift;
my $self = $class->SUPER::_init(@_);
$self->faspport($self->default_faspport) unless defined $self->faspport;
# Other defaults
# Other defaults...
$self;
}

sub bwcap { shift->_query_param('bwcap', @_); }
sub policy { shift->_query_param('policy', @_); }
sub httpport { shift->_query_param('httpport', @_); }
sub targetrate { shift->_query_param('targetrate', @_); }
sub default_faspport { 33001 }

sub faspport
{
my $self = shift;
return $self->_query_param('port', @_) if @_;
return $self->query_param('port', @_) if @_;

# No need to entertain a list
my $port = $self->query_param('port') ||
$self->query_param('faspport');
$port;
Expand All @@ -43,19 +50,6 @@ sub as_ssh
$ssh;
}

sub _query_param
{
my ($self, $param, $value) = @_;

# Do we need to accept multiple args here?
if($value) {
$self->query_param($param, $value);
return;
}

$self->query_param($param);
}

1;

=pod
Expand Down
8 changes: 7 additions & 1 deletion t/fasp.t
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

use URI;
use Test::More tests => 15;
use Test::More tests => 17;

my $uri = URI->new('fasp://example.com');
isa_ok($uri, 'URI::fasp');
Expand Down Expand Up @@ -32,3 +32,9 @@ is($uri->targetrate, 100000);
my $ssh = $uri->as_ssh;
isa_ok($ssh, 'URI::ssh');
is($ssh->port, 33001);
is($ssh->query, undef);

# Aspera uses "port", we use that and "faspport"
$uri = URI->new('fasp://example.com:33001?faspport=5000');
is($uri->faspport, 5000);

0 comments on commit 7014447

Please sign in to comment.