blib/lib/Encoding/BER/Dumper.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 55 CC 4 SCAR 17.0
CC
4
Cov
0%
decanon
12.0
import
6.0
pl2ber
2.0
CRAP 5.5
1 # -*- perl -*-
2  
3 # Copyright (c) 2007 by Jeff Weisberg
4 # Author: Jeff Weisberg <jaw+pause @ tcp4me.com>
5 # Created: 2007-Feb-04 16:43 (EST)
6 # Function: dump perl data to/from ber
7 #
8 # $Id: Dumper.pm,v 1.5 2007/03/06 02:50:10 jaw Exp $
9  
10 package Encoding::BER::Dumper;
11 use Encoding::BER;
12 use vars qw($VERSION);
13 $VERSION = '1.00';
14 use strict;
15  
16 sub pl2ber {
17 my $pl = shift;
18  
19 my $enc = Encoding::BER->new(acanonical => 1);
20 $enc->encode($pl);
21 }
22  
23 sub ber2pl {
24 my $ber = shift;
25
26 my $dec = Encoding::BER->new( );
27 $dec->add_tag('application', 'constructed', 'berdump_hash', 3);
28 decanon($dec->decode($ber));
29 }
30  
31 sub decanon {
32 my $n = shift;
33 my $v = $n->{value};
34  
35 return $v unless ref $v;
36  
37 my @v;
38 for my $r (@$v){
39 push @v, decanon($r);
40 }
41  
42 if( $n->{type}[2] eq 'berdump_hash' ){
43 return { @v };
44 }else{
45 return \@v;
46 }
47 }
48  
49 sub import {
50 my $pkg = shift;
51 my $caller = caller;
52  
53 for my $f ('pl2ber', 'ber2pl'){
54 no strict;
55 my $fnc = $pkg->can($f);
56 next unless $fnc;
57 *{$caller . '::' . $f} = $fnc;
58 }
59 }
60  
61 =head1 NAME
62  
63 Encoding::BER::Dumper - Perl module for dumping Perl objects from/to BER
64  
65 =head1 SYNOPSIS
66  
67 use Encoding::BER::Dumper;
68  
69 $ber = pl2ber( $perl );
70 $perl = ber2pl( $ber );
71  
72 =head1 DESCRIPTION
73  
74  
75 =head1 EXPORTS
76  
77 The following methods are exported:
78  
79 ber2pl, pl2ber
80  
81 =head1 BUGS
82  
83 Not all types of things perl can be encoded in BER.
84  
85 =head1 SEE ALSO
86  
87 Yellowstone National Park.
88 Encoding::BER, Data::Dumper, XML::Dumper
89  
90 =head1 AUTHOR
91  
92 Jeff Weisberg - http://www.tcp4me.com/
93  
94 =cut
95 ;
96
97  
98 1;