File Coverage

blib/lib/IPC/Manager/Message.pm
Criterion Covered Total %
statement 33 40 82.5
branch 6 12 50.0
condition 5 9 55.5
subroutine 10 11 90.9
pod 3 4 75.0
total 57 76 75.0


line stmt bran cond sub pod time code
1             package IPC::Manager::Message;
2 2     2   12 use strict;
  2         4  
  2         86  
3 2     2   7 use warnings;
  2         4  
  2         138  
4              
5             our $VERSION = '0.000005';
6              
7 2     2   11 use Carp qw/croak/;
  2         4  
  2         157  
8 2     2   13 use Time::HiRes qw/time/;
  2         4  
  2         26  
9 2     2   136 use Scalar::Util qw/blessed/;
  2         5  
  2         135  
10 2     2   1010 use Test2::Util::UUID qw/gen_uuid/;
  2         3632  
  2         17  
11              
12 2         17 use Object::HashBase qw{
13            
14            
15            
16            
17            
18            
19 2     2   4213 };
  2         4  
20              
21             sub init {
22 52     52 0 1202 my $self = shift;
23              
24 52 50       137 croak "'from' is a required attribute" unless $self->{+FROM};
25 52 50       144 croak "'content' is a required attribute" unless defined $self->{+CONTENT};
26              
27 52 0 33     107 croak "Message must either have a 'to' or 'broadcast' attribute" unless $self->{+TO} || $self->{+BROADCAST};
28              
29 52   66     181 $self->{+ID} //= gen_uuid();
30 52   66     629 $self->{+STAMP} //= time;
31             }
32              
33             sub is_terminate {
34 8     8 1 15 my $self = shift;
35              
36 8 50       36 my $content = $self->{+CONTENT} or return 0;
37 8 100       31 return 0 unless ref($content) eq 'HASH';
38 6 50       32 return 1 if $content->{terminate};
39 0         0 return 0;
40             }
41              
42 26     26 1 41 sub TO_JSON { +{%{$_[0]}} }
  26         686  
43              
44             sub clone {
45 0     0 1   my $self = shift;
46 0           my %params = @_;
47 0           my $copy = {%$self};
48 0           delete $copy->{+ID};
49 0           $copy = {%$copy, %params};
50 0           return blessed($self)->new($copy);
51             }
52              
53             1;
54              
55             __END__