File Coverage

blib/lib/Plack/App/ServiceStatus/NetStomp.pm
Criterion Covered Total %
statement 29 29 100.0
branch 2 2 100.0
condition n/a
subroutine 9 9 100.0
pod 0 1 0.0
total 40 41 97.5


line stmt bran cond sub pod time code
1             package Plack::App::ServiceStatus::NetStomp;
2              
3             # ABSTRACT: Check Net::Stomp connection
4              
5             our $VERSION = '0.911'; # VERSION
6              
7 1     1   80371 use 5.018;
  1         7  
8 1     1   6 use strict;
  1         2  
  1         18  
9 1     1   5 use warnings;
  1         2  
  1         38  
10 1     1   520 use Module::Runtime qw(require_module);
  1         1753  
  1         9  
11 1     1   546 use Try::Tiny;
  1         2081  
  1         242  
12              
13             sub check {
14 4     4 0 9018 my ( $class, $stomp ) = @_;
15              
16 4 100       24 if ( ref $stomp eq 'CODE' ) {
17 2         6 $stomp = $stomp->();
18             }
19              
20 4         21 require_module 'Net::Stomp::Frame';
21 4         184 my $reconnect_attempts = $stomp->reconnect_attempts();
22             return try {
23 4     4   337 $stomp->reconnect_attempts(1);
24 4         285 my $transaction_id = $stomp->_get_next_transaction;
25 4         236 my $begin_frame = Net::Stomp::Frame->new(
26             {
27             command => 'BEGIN',
28             headers => { transaction => $transaction_id }
29             }
30             );
31 4         35 $stomp->send_frame($begin_frame);
32 2         120 my $abort_frame = Net::Stomp::Frame->new(
33             {
34             command => 'ABORT',
35             headers => { transaction => $transaction_id }
36             }
37             );
38 2         16 $stomp->send_frame($abort_frame);
39 2         116 return 'ok';
40             }
41             catch {
42 2     2   215 return 'nok', 'Not connected: ' . $_;
43             }
44             finally {
45 4     4   73 $stomp->reconnect_attempts($reconnect_attempts);
46             }
47 4         324 }
48              
49             1;
50              
51             __END__