| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package URI::amqp; | 
| 2 | 3 |  |  | 3 |  | 1757 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 66 |  | 
| 3 | 3 |  |  | 3 |  | 12 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 89 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '0.1.3'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 3 |  |  | 3 |  | 1135 | use URI::QueryParam; | 
|  | 3 |  |  |  |  | 1775 |  | 
|  | 3 |  |  |  |  | 80 |  | 
| 8 | 3 |  |  | 3 |  | 15 | use URI::Escape qw(uri_unescape); | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 144 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 3 |  |  | 3 |  | 361 | use parent qw(URI::_server URI::_userpass); | 
|  | 3 |  |  |  |  | 217 |  | 
|  | 3 |  |  |  |  | 17 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 13 |  |  | 13 | 1 | 23472 | sub default_port { 5672 } | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 NAME | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | URI::amqp - AMQP (RabbitMQ) URI | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | my $uri = URI->new('amqp://user:pass@host.domain:1234/'); | 
| 21 |  |  |  |  |  |  | my $ar = AnyEvent::RabbitMQ->new->load_xml_spec()->connect( | 
| 22 |  |  |  |  |  |  | host      => $uri->host, | 
| 23 |  |  |  |  |  |  | port      => $uri->port, | 
| 24 |  |  |  |  |  |  | user      => $uri->user, | 
| 25 |  |  |  |  |  |  | pass      => $uri->password, | 
| 26 |  |  |  |  |  |  | vhost     => $uri->vhost, | 
| 27 |  |  |  |  |  |  | tls       => $uri->secure, | 
| 28 |  |  |  |  |  |  | heartbeat => scalar $uri->query_param('heartbeat'), | 
| 29 |  |  |  |  |  |  | ... | 
| 30 |  |  |  |  |  |  | ); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | URI extension for AMQP protocol (L) | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =head1 EXTENDED METHODS | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head2 vhost | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | vhost is path part of URI | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | slash C> on start is removed (this is different with C method) | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | return C if vhost not defined (should be used default of module which use this URI module) | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =cut | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub vhost { | 
| 49 | 19 |  |  | 19 | 1 | 15678 | my ($self) = @_; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 19 |  |  |  |  | 60 | my $vhost = $self->path; | 
| 52 | 19 |  |  |  |  | 228 | $vhost =~ s/^\///; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 19 | 100 |  |  |  | 76 | return if !length $vhost; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 9 |  |  |  |  | 28 | return uri_unescape($vhost); | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head2 query_param | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | return query parameters (L) | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | implement by L module | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head2 as_net_amqp_rabbitmq | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | return tuplet of C<($host, $options)> which works with L C method | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | use URI; | 
| 70 |  |  |  |  |  |  | use Net::AMQP::RabbitMQ; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | my $uri = URI->new('amqp://guest:guest@localhost'); | 
| 73 |  |  |  |  |  |  | my $mq = Net::AMQP::RabbitMQ->new(); | 
| 74 |  |  |  |  |  |  | $mq->connect($uri->as_net_amqp_rabbitmq_options); | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =cut | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub as_net_amqp_rabbitmq { | 
| 79 | 2 |  |  | 2 | 1 | 2547 | my ($self) = @_; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 2 |  |  |  |  | 5 | my $options = {}; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 2 | 100 |  |  |  | 10 | $options->{user}        = $self->user                              if defined $self->user; | 
| 84 | 2 | 100 |  |  |  | 234 | $options->{password}    = $self->password                          if defined $self->password; | 
| 85 | 2 | 50 |  |  |  | 88 | $options->{port}        = $self->port                              if defined $self->port; | 
| 86 | 2 | 100 |  |  |  | 53 | $options->{vhost}       = $self->vhost                             if defined $self->vhost; | 
| 87 | 2 | 100 |  |  |  | 17 | $options->{channel_max} = scalar $self->query_param('channel_max') if defined $self->query_param('channel_max'); | 
| 88 | 2 | 100 |  |  |  | 304 | $options->{frame_max}   = scalar $self->query_param('frame_max')   if defined $self->query_param('frame_max'); | 
| 89 | 2 | 100 |  |  |  | 278 | $options->{heartbeat}   = scalar $self->query_param('heartbeat')   if defined $self->query_param('heartbeat'); | 
| 90 | 2 | 100 |  |  |  | 407 | $options->{timeout} = scalar $self->query_param('connection_timeout') | 
| 91 |  |  |  |  |  |  | if scalar $self->query_param('connection_timeout'); | 
| 92 | 2 | 100 |  |  |  | 295 | $options->{ssl}             = $self->secure                           if $self->secure; | 
| 93 | 2 | 100 |  |  |  | 7 | $options->{ssl_verify_host} = scalar $self->query_param('verify')     if defined $self->query_param('verify'); | 
| 94 | 2 | 100 |  |  |  | 280 | $options->{ssl_cacert}      = scalar $self->query_param('cacertfile') if defined $self->query_param('cacertfile'); | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 2 |  |  |  |  | 282 | return ($self->host, $options); | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head2 as_anyevent_rabbitmq | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | return options which works with L C method | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | use URI; | 
| 104 |  |  |  |  |  |  | use AnyEvent::RabbitMQ; | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | my $cv = AnyEvent->condvar; | 
| 107 |  |  |  |  |  |  | my $uri = URI->new('amqp://user:pass@host.domain:1234/'); | 
| 108 |  |  |  |  |  |  | my $ar = AnyEvent::RabbitMQ->new->load_xml_spec()->connect( | 
| 109 |  |  |  |  |  |  | $uri->as_anyevent_rabbitmq(), | 
| 110 |  |  |  |  |  |  | on_success => sub { | 
| 111 |  |  |  |  |  |  | ... | 
| 112 |  |  |  |  |  |  | }, | 
| 113 |  |  |  |  |  |  | ... | 
| 114 |  |  |  |  |  |  | ); | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =cut | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | sub as_anyevent_rabbitmq { | 
| 119 | 2 |  |  | 2 | 1 | 1755 | my ($self) = @_; | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 2 |  |  |  |  | 5 | my $options = {}; | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 2 | 50 |  |  |  | 10 | $options->{host}  = $self->host     if defined $self->host; | 
| 124 | 2 | 50 |  |  |  | 246 | $options->{port}  = $self->port     if defined $self->port; | 
| 125 | 2 | 100 |  |  |  | 57 | $options->{user}  = $self->user     if defined $self->user; | 
| 126 | 2 | 100 |  |  |  | 90 | $options->{pass}  = $self->password if defined $self->password; | 
| 127 | 2 | 100 |  |  |  | 86 | $options->{vhost} = $self->vhost    if defined $self->vhost; | 
| 128 | 2 | 100 |  |  |  | 15 | $options->{timeout} = scalar $self->query_param('connection_timeout') | 
| 129 |  |  |  |  |  |  | if defined $self->query_param('connection_timeout'); | 
| 130 | 2 | 100 |  |  |  | 310 | $options->{tls} = $self->secure if $self->secure; | 
| 131 | 2 | 100 |  |  |  | 7 | $options->{tune}{heartbeat} = scalar $self->query_param('heartbeat') if defined $self->query_param('heartbeat'); | 
| 132 | 2 | 100 |  |  |  | 284 | $options->{tune}{channel_max} = scalar $self->query_param('channel_max') | 
| 133 |  |  |  |  |  |  | if defined $self->query_param('channel_max'); | 
| 134 | 2 | 100 |  |  |  | 287 | $options->{tune}{frame_max} = scalar $self->query_param('frame_max') if defined $self->query_param('frame_max'); | 
| 135 |  |  |  |  |  |  |  | 
| 136 | 2 |  |  |  |  | 293 | return $options; | 
| 137 |  |  |  |  |  |  | } | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =head1 LIMITATIONS | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | module doesn't support correct C (reverse) method (yet) | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =head1 LICENSE | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | Copyright (C) Avast Software. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 148 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =head1 AUTHOR | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | Jan Seidl Eseidl@avast.comE | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =cut | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | 1; |