Model/JabberRPC.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Helper/Model/JabberRPC.pm ↑ Summary
1 package Catalyst::Model::JabberRPC;
2 1 ▶use base qw/Catalyst::Model/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use NEXT;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶use Jabber::RPC::Client;
Subroutine BEGIN: called CC=1 SCAR=2.6
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__
« Helper/Model/JabberRPC.pm ↑ Summary