line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IPC::Transit::Router; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$IPC::Transit::Router::VERSION = '1.132260'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
835
|
use strict;use warnings; |
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
7
|
1
|
|
|
1
|
|
31
|
use 5.006; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
857
|
use Message::Router qw(mroute mroute_config); |
|
1
|
|
|
|
|
3785
|
|
|
1
|
|
|
|
|
72
|
|
9
|
1
|
|
|
1
|
|
664
|
use IPC::Transit; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
use vars qw(@ISA @EXPORT_OK); |
12
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
@EXPORT_OK = qw(troute troute_config); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub troute { |
16
|
|
|
|
|
|
|
my $message = shift; |
17
|
|
|
|
|
|
|
return mroute($message); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
sub troute_config { |
20
|
|
|
|
|
|
|
my $new_config = shift; |
21
|
|
|
|
|
|
|
foreach my $route (@{$new_config->{routes}}) { |
22
|
|
|
|
|
|
|
foreach my $forward (@{$route->{forwards}}) { |
23
|
|
|
|
|
|
|
$forward->{handler} = 'IPC::Transit::Router::handler'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
return mroute_config($new_config); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub handler { |
30
|
|
|
|
|
|
|
my %args = @_; |
31
|
|
|
|
|
|
|
if($args{forward}->{destination}) { |
32
|
|
|
|
|
|
|
return IPC::Transit::send( |
33
|
|
|
|
|
|
|
message => $args{message}, |
34
|
|
|
|
|
|
|
qname => $args{forward}->{qname}, |
35
|
|
|
|
|
|
|
destination => $args{forward}->{destination}, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} else { |
38
|
|
|
|
|
|
|
return IPC::Transit::send(message => $args{message}, qname => $args{forward}->{qname}); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
IPC::Transit::Router - Allows fast, simple routing of Transit messages |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use IPC::Transit; |
51
|
|
|
|
|
|
|
use IPC::Transit::Router qw(troute troute_config); |
52
|
|
|
|
|
|
|
troute_config({ |
53
|
|
|
|
|
|
|
routes => [ |
54
|
|
|
|
|
|
|
{ match => { |
55
|
|
|
|
|
|
|
a => 'b', |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
forwards => [ |
58
|
|
|
|
|
|
|
{ qname => 'some_q' } |
59
|
|
|
|
|
|
|
], |
60
|
|
|
|
|
|
|
transform => { |
61
|
|
|
|
|
|
|
x => 'y', |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
], |
65
|
|
|
|
|
|
|
}); |
66
|
|
|
|
|
|
|
troute({a => 'b'}); |
67
|
|
|
|
|
|
|
my $ret = IPC::Transit::receive(qname => 'some_q'); |
68
|
|
|
|
|
|
|
#$ret contains { a => 'b', x => 'y' } |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This library allows fast, simple routing of Transit messages |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 FUNCTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 troute_config($config); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The config used by all mroute calls |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 troute($message); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Pass $message through the config; this will emit zero or more IPC::Transit |
83
|
|
|
|
|
|
|
messages. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 TODO |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
A config validator. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 BUGS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
None known. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Dana M. Diederich <diederich@gmail.com> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Copyright 2012,2013 Dana M. Diederich. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
102
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
103
|
|
|
|
|
|
|
copy of the full license at: |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|