line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Model::JabberRPC; |
2
|
1
|
|
|
1
|
|
33003
|
use base qw/Catalyst::Model/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
927
|
|
3
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
91
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7683
|
use NEXT; |
|
1
|
|
|
|
|
5902
|
|
|
1
|
|
|
|
|
48
|
|
7
|
1
|
|
|
1
|
|
15
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
81
|
|
8
|
1
|
|
|
1
|
|
622
|
use Jabber::RPC::Client; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
|
|
|
|
|
|
my ($class, $c, $config) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $self = $class->NEXT::new($c, $config); |
18
|
|
|
|
|
|
|
$self->config($config); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %jabber_config = %{ $self->config }; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
for my $key (qw/server identauth endpoint/) { |
23
|
|
|
|
|
|
|
croak "Must provide $key" unless exists $jabber_config{$key}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $client = Jabber::RPC::Client->new(%jabber_config); |
27
|
|
|
|
|
|
|
croak "Can't create Jabber::RPC::Client object" |
28
|
|
|
|
|
|
|
unless UNIVERSAL::isa($client, 'Jabber::RPC::Client'); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$self->{jabber_client} = $client; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$c->log->debug("New Jabber::RPC::Client created") if $c->debug; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub AUTOLOAD { |
39
|
|
|
|
|
|
|
my ($self, @args) = @_; |
40
|
|
|
|
|
|
|
our $AUTOLOAD; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return if $AUTOLOAD =~ /::DESTROY$/; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
(my $op = $AUTOLOAD) =~ s/^.*:://; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $client = $self->{jabber_client}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if (my $msg = $client->$op(@args)) { |
49
|
|
|
|
|
|
|
if (ref $msg eq 'HASH' && exists $msg->{faultString}) { |
50
|
|
|
|
|
|
|
croak $msg->{faultString}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
return $msg; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
|
|
|
|
|
|
# If the execution failed by some reason we simply die |
56
|
|
|
|
|
|
|
croak $client->lastfault; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Catalyst::Model::JabberRPC - JabberRPC model class for Catalyst |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Model |
72
|
|
|
|
|
|
|
__PACKAGE__->config( |
73
|
|
|
|
|
|
|
server => 'myserver.org', |
74
|
|
|
|
|
|
|
identauth => 'user:password', |
75
|
|
|
|
|
|
|
endpoint => 'jrpc.myserver.org/rpc-server', |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Controller |
79
|
|
|
|
|
|
|
sub default : Private { |
80
|
|
|
|
|
|
|
my ($self, $c) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $result; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
eval { |
85
|
|
|
|
|
|
|
$result = $c->model('RemoteService')->call('examples.getStateName', 5); |
86
|
|
|
|
|
|
|
$c->stash->{value} = $result; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
if ($@) { |
89
|
|
|
|
|
|
|
... |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
... |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 DESCRIPTION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This model class uses L<Jabber::RPC::Client> to invoke remote procedure calls |
98
|
|
|
|
|
|
|
using XML-RPC calls over Jabber. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 CONFIGURATION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
You can pass the same configuration fields as when you call |
103
|
|
|
|
|
|
|
L<Jabber::RPC::Client>. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 METHODS |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 General |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Take a look at L<Jabber::RPC::Client> to see the method you can call. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 new |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Called from Catalyst. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 NOTES |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This module will croak (die) if the execution of the remote proceduce failed, |
118
|
|
|
|
|
|
|
and also if the return message is a hashref which contain a key named |
119
|
|
|
|
|
|
|
B<faultString>. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SEE ALSO |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
L<Jabber::RPC::Client>, L<Catalyst::Model> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Florian Merges, E<lt>fmerges@cpan.orgE<gt> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
132
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |