blib/lib/Crypt/Perl/X/Base.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 52 CC 4 SCAR 14.3
CC
4
Cov
0%
new
6.0
_check_overload
6.0
__spew
6.0
CRAP 4.2
1 package Crypt::Perl::X::Base;
2  
3 use strict;
4 use warnings;
5  
6 use Carp ();
7  
8 sub new {
9 my ( $class, $string, $props_hr ) = @_;
10  
11 $class->_check_overload();
12  
13 my %attrs = $props_hr ? %$props_hr : ();
14  
15 return bless [ $string, \%attrs ], $class;
16 }
17  
18 sub get {
19 my ( $self, $attr ) = @_;
20  
21 #Do we need to clone this? Could JSON suffice, or do we need Clone?
22 return $self->[1]{$attr};
23 }
24  
25 sub to_string {
26 my ($self) = @_;
27  
28 return sprintf '%s: %s', ref($self), $self->[0];
29 }
30  
31 #----------------------------------------------------------------------
32  
33 my %_OVERLOADED;
34  
35 sub _check_overload {
36 my ( $class, $str ) = @_;
37  
38 #cf. eval_bug.readme
39 my $eval_err = $@;
40  
41 $_OVERLOADED{$class} ||= eval qq{
42 package $class;
43 use overload (q<""> => __PACKAGE__->can('__spew'));
44 1;
45 };
46  
47 #Should never happen as long as overload.pm is available.
48 warn if !$_OVERLOADED{$class};
49  
50 $@ = $eval_err;
51  
52 return;
53 }
54  
55 sub __spew {
56 my ($self) = @_;
57  
58 my $spew = $self->to_string();
59  
60 if ( substr( $spew, -1 ) ne "\n" ) {
61 $spew .= Carp::longmess();
62 }
63  
64 return $spew;
65 }
66  
67 1;