| 1 | package URI::amqp; | ||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | our $VERSION = '0.1.1'; | |||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use URI::QueryParam; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use parent qw(URI::_server URI::_userpass); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 9 | ▶ | sub default_port { 5672 } | ||||||||
|
Subroutine
default_port: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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<https://www.rabbitmq.com/uri-spec.html>) | ||||||||||
| 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<path> method) | ||||||||||
| 43 | |||||||||||
| 44 | return C<undef> if vhost not defined (should be used default of module which use this URI module) | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | sub vhost { | ||||||||||
| 49 | 15 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
vhost: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 50 | |||||||||||
| 51 | 15 | my $vhost = $self->path; | |||||||||
| 52 | 15 | $vhost =~ s/^\///; | |||||||||
| 53 | |||||||||||
| 54 | 15 | ▶ | return if !length $vhost; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 7 | return uri_unescape($vhost); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | =head2 query_param | ||||||||||
| 60 | |||||||||||
| 61 | return query parameters (L<https://www.rabbitmq.com/uri-query-parameters.html>) | ||||||||||
| 62 | |||||||||||
| 63 | implement by L<URI::QueryParam> module | ||||||||||
| 64 | |||||||||||
| 65 | =head2 as_net_amqp_rabbitmq | ||||||||||
| 66 | |||||||||||
| 67 | return tuplet of C<($host, $options)> which works with L<Net::AMQP::RabbitMQ> C<connect> 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 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
as_net_amqp_rabbitmq: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 80 | |||||||||||
| 81 | return ( | ||||||||||
| 82 | 1 | $self->host, | |||||||||
| 83 | { | ||||||||||
| 84 | user => $self->user, | ||||||||||
| 85 | password => $self->password, | ||||||||||
| 86 | port => $self->port, | ||||||||||
| 87 | vhost => $self->vhost, | ||||||||||
| 88 | channel_max => scalar $self->query_param('channel_max'), | ||||||||||
| 89 | frame_max => scalar $self->query_param('frame_max'), | ||||||||||
| 90 | heartbeat => scalar $self->query_param('heartbeat'), | ||||||||||
| 91 | timeout => scalar $self->query_param('connection_timeout'), | ||||||||||
| 92 | ssl => $self->secure, | ||||||||||
| 93 | ssl_verify_host => scalar $self->query_param('verify'), | ||||||||||
| 94 | ssl_cacert => scalar $self->query_param('cacertfile'), | ||||||||||
| 95 | } | ||||||||||
| 96 | ); | ||||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | =head2 as_anyevent_rabbitmq | ||||||||||
| 100 | |||||||||||
| 101 | return options which works with L<AnyEvent::RabbitMQ> C<connect> 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 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
as_anyevent_rabbitmq: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 120 | |||||||||||
| 121 | return { | ||||||||||
| 122 | 1 | host => $self->host, | |||||||||
| 123 | port => $self->port, | ||||||||||
| 124 | user => $self->user, | ||||||||||
| 125 | pass => $self->password, | ||||||||||
| 126 | vhost => $self->vhost, | ||||||||||
| 127 | timeout => scalar $self->query_param('connection_timeout'), | ||||||||||
| 128 | tls => $self->secure, | ||||||||||
| 129 | tune => { | ||||||||||
| 130 | heartbeat => scalar $self->query_param('heartbeat'), | ||||||||||
| 131 | channel_max => scalar $self->query_param('channel_max'), | ||||||||||
| 132 | frame_max => scalar $self->query_param('frame_max'), | ||||||||||
| 133 | }, | ||||||||||
| 134 | }; | ||||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | =head1 LIMITATIONS | ||||||||||
| 138 | |||||||||||
| 139 | module doesn't support correct C<canonpath> (reverse) method (yet) | ||||||||||
| 140 | |||||||||||
| 141 | =head1 LICENSE | ||||||||||
| 142 | |||||||||||
| 143 | Copyright (C) Avast Software. | ||||||||||
| 144 | |||||||||||
| 145 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 146 | it under the same terms as Perl itself. | ||||||||||
| 147 | |||||||||||
| 148 | =head1 AUTHOR | ||||||||||
| 149 | |||||||||||
| 150 | Jan Seidl E<lt>seidl@avast.comE<gt> | ||||||||||
| 151 | |||||||||||
| 152 | =cut | ||||||||||
| 153 | |||||||||||
| 154 | 3 | 1; | |||||||||