File Coverage

blib/lib/Net/WebSocket/Message.pm
Criterion Covered Total %
statement 19 26 73.0
branch 3 4 75.0
condition n/a
subroutine 6 8 75.0
pod 0 5 0.0
total 28 43 65.1


line stmt bran cond sub pod time code
1             package Net::WebSocket::Message;
2              
3 4     4   101826 use strict;
  4         24  
  4         90  
4 4     4   17 use warnings;
  4         6  
  4         76  
5              
6 4     4   684 use Call::Context ();
  4         682  
  4         896  
7              
8             sub new {
9 10 50   10 0 60 if (!$_[1]->isa('Net::WebSocket::Frame')) {
10 0         0 die( (caller 0)[3] . ' needs at least one Net::WebSocket::Frame object!' );
11             }
12              
13 10         43 return bless \@_, shift;
14             }
15              
16             sub get_frames {
17 0     0 0 0 my ($self) = @_;
18              
19 0         0 Call::Context::must_be_list();
20              
21 0         0 return @$self;
22             }
23              
24             sub get_payload {
25 12     12 0 138 my ($self) = @_;
26              
27 12         27 return join( q<>, map { $_->get_payload() } @$self );
  15         52  
28             }
29              
30             sub to_bytes {
31 0     0 0 0 my ($self) = @_;
32              
33 0         0 return join( q<>, map { $_->to_bytes() } @$self );
  0         0  
34             }
35              
36             #----------------------------------------------------------------------
37             # Static function that auto-loads the actual message class.
38              
39             sub create_from_frames {
40 10     10 0 50 my $type = $_[0]->get_type();
41              
42 10         28 my $class = __PACKAGE__ . "::$type";
43 10 100       74 if (!$class->can('new')) {
44 5         17 Module::Load::load($class);
45             }
46              
47 10         88 return $class->new(@_);
48             }
49              
50             1;