1package Net::LibLO::Address; 2 3################ 4# 5# liblo: perl bindings 6# 7# Copyright 2005 Nicholas J. Humfrey <njh@aelius.com> 8# 9 10use Carp; 11use Net::LibLO; 12use strict; 13 14 15 16sub new { 17 my $class = shift; 18 my $self = { address => undef }; 19 20 # Bless the hash into an object 21 bless $self, $class; 22 23 # 1 parameter = lo_addres, URL or port 24 # 2 parameters = host and port 25 if (scalar(@_)==1) { 26 27 # Is it a number ? 28 if (ref($_[0]) eq 'lo_address') { 29 my ($address) = @_; 30 $self->{address} = $address; 31 # Don't free memory we didn't allocate 32 $self->{dontfree} = 1; 33 } elsif ($_[0] =~ /^\d+$/) { 34 my ($port) = @_; 35 $self->{address} = Net::LibLO::lo_address_new( 'localhost', $port ); 36 } else { 37 my ($url) = @_; 38 $self->{address} = Net::LibLO::lo_address_new_from_url( $url ); 39 } 40 41 } elsif (scalar(@_)==2) { 42 my ($host, $port) = @_; 43 $self->{address} = Net::LibLO::lo_address_new( $host, $port ); 44 45 } else { 46 croak( "Invalid number of parameters" ); 47 } 48 49 # Was there an error ? 50 if (!defined $self->{address} || $self->errno()) { 51 carp("Error creating lo_address"); 52 undef $self; 53 } 54 55 return $self; 56} 57 58sub errno { 59 my $self=shift; 60 61 return Net::LibLO::lo_address_errno( $self->{address} ); 62} 63 64sub errstr { 65 my $self=shift; 66 67 return Net::LibLO::lo_address_errstr( $self->{address} ); 68} 69 70 71sub get_hostname { 72 my $self=shift; 73 74 return Net::LibLO::lo_address_get_hostname( $self->{address} ); 75} 76 77sub get_port { 78 my $self=shift; 79 80 return Net::LibLO::lo_address_get_port( $self->{address} ); 81} 82 83sub get_url { 84 my $self=shift; 85 86 return Net::LibLO::lo_address_get_url( $self->{address} ); 87} 88 89 90sub DESTROY { 91 my $self=shift; 92 93 if (defined $self->{address}) { 94 # Don't free memory we didn't allocate 95 unless ($self->{dontfree}) { 96 Net::LibLO::lo_address_free( $self->{address} ); 97 } 98 undef $self->{address}; 99 } 100} 101 102 1031; 104 105__END__ 106 107=pod 108 109=head1 NAME 110 111Net::LibLO::Address 112 113=head1 SYNOPSIS 114 115 use Net::LibLO::Address; 116 117 my $addr = new Net::LibLO::Address( 'localhost', 3340 ); 118 my $port = $addr->get_port(); 119 my $hostname = $addr->get_hostname(); 120 121 122=head1 DESCRIPTION 123 124Net::LibLO::Address is a perl class which represents an address to send messages to 125 126=over 4 127 128=item B<new( hostname, port )> 129 130Create a new OSC address, from a hostname and port 131 132=item B<new( port )> 133 134Create a new OSC address, from port. Localhost is assumed. 135 136=item B<new( url )> 137 138Create a new OSC address, from a URL 139 140=item B<get_hostname( )> 141 142Returns the hostname portion of an OSC address. 143 144=item B<get_port( )> 145 146Returns the port portion of an OSC address. 147 148=item B<get_url( )> 149 150Returns the URL for an OSC address. 151 152=item B<errno( )> 153 154Return the error number from the last failure. 155 156=item B<errstr( )> 157 158Return the error string from the last failure. 159 160=back 161 162=head1 AUTHOR 163 164Nicholas J. Humfrey, njh@aelius.com 165 166=head1 COPYRIGHT AND LICENSE 167 168Copyright (C) 2005 Nicholas J. Humfrey 169 170This program is free software; you can redistribute it and/or modify 171it under the terms of the GNU General Public License as published by 172the Free Software Foundation; either version 2 of the License, or 173(at your option) any later version. 174 175This program is distributed in the hope that it will be useful, 176but WITHOUT ANY WARRANTY; without even the implied warranty of 177MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 178GNU General Public License for more details. 179 180=cut 181