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.913'; # VERSION
6              
7 2     2   364563 use 5.018;
  2         7  
8 2     2   11 use strict;
  2         5  
  2         54  
9 2     2   8 use warnings;
  2         4  
  2         140  
10 2     2   994 use Module::Runtime qw(require_module);
  2         5275  
  2         12  
11 2     2   1154 use Try::Tiny;
  2         4641  
  2         708  
12              
13             sub check {
14 4     4 0 295611 my ( $class, $stomp ) = @_;
15              
16 4 100       20 if ( ref $stomp eq 'CODE' ) {
17 2         7 $stomp = $stomp->();
18             }
19              
20 4         23 require_module 'Net::Stomp::Frame';
21 4         215 my $reconnect_attempts = $stomp->reconnect_attempts();
22             return try {
23 4     4   326 $stomp->reconnect_attempts(1);
24 4         351 my $transaction_id = $stomp->_get_next_transaction;
25 4         328 my $begin_frame = Net::Stomp::Frame->new(
26             {
27             command => 'BEGIN',
28             headers => { transaction => $transaction_id }
29             }
30             );
31 4         41 $stomp->send_frame($begin_frame);
32 2         138 my $abort_frame = Net::Stomp::Frame->new(
33             {
34             command => 'ABORT',
35             headers => { transaction => $transaction_id }
36             }
37             );
38 2         17 $stomp->send_frame($abort_frame);
39 2         183 return 'ok';
40             }
41             catch {
42 2     2   183 return 'nok', 'Not connected: ' . $_;
43             }
44             finally {
45 4     4   86 $stomp->reconnect_attempts($reconnect_attempts);
46             }
47 4         477 }
48              
49             1;
50              
51             __END__