File Coverage

blib/lib/Event/RPC/Message/SerialiserBase.pm
Criterion Covered Total %
statement 16 19 84.2
branch 2 12 16.6
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 23 38 60.5


line stmt bran cond sub pod time code
1             # $Id: Message.pm,v 1.9 2014-01-28 15:40:10 joern Exp $
2              
3             #-----------------------------------------------------------------------
4             # Copyright (C) 2002-2015 by Jörn Reder .
5             # All Rights Reserved. See file COPYRIGHT for details.
6             #
7             # This module is part of Event::RPC, which is free software; you can
8             # redistribute it and/or modify it under the same terms as Perl itself.
9             #-----------------------------------------------------------------------
10              
11             package Event::RPC::Message::SerialiserBase;
12              
13 18     18   110 use base Event::RPC::Message;
  18         25  
  18         1328  
14              
15 18     18   78 use strict;
  18         36  
  18         339  
16 18     18   89 use utf8;
  18         35  
  18         169  
17              
18             sub UNIVERSAL::FREEZE {
19 1     1 0 5 my ($object, $serialiser) = @_;
20 1         17 my ($ref_type) = "$object" =~ /=(\w+)\(/;
21 1         17 return $ref_type eq 'HASH' ? [ $ref_type, [%{$object}] ] :
22 0         0 $ref_type eq 'ARRAY' ? [ $ref_type, [@{$object}] ] :
23 1 0       7 $ref_type eq 'SCALAR' ? [ $ref_type, ${$object} ] :
  0 0       0  
    50          
24             die "Unsupported reference type '$ref_type'";
25             }
26              
27             sub UNIVERSAL::THAW {
28 11     11 0 33 my ($class, $serialiser, $obj) = @_;
29 11         143 return $obj->[0] eq 'HASH' ? bless { @{$obj->[1]} }, $class :
30 11 0       66 $obj->[0] eq 'ARRAY' ? bless [ @{$obj->[1]} ], $class :
  0 0          
    50          
31             $obj->[0] eq 'SCALAR' ? bless \ $obj->[1], $class :
32             die "Unsupported reference type '$obj->[0]'";
33             }
34              
35             1;
36              
37             __END__