| 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 | 1 | ▶ | use Encoding::BER; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | $VERSION = '1.00'; | |||||||||
| 14 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | sub pl2ber { | ||||||||
|
Subroutine
pl2ber: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 1 | my $pl = shift; | |||||||||
| 18 | |||||||||||
| 19 | 1 | my $enc = Encoding::BER->new(acanonical => 1); | |||||||||
| 20 | 1 | $enc->encode($pl); | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub ber2pl { | ||||||||
|
Subroutine
ber2pl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 1 | my $ber = shift; | |||||||||
| 25 | |||||||||||
| 26 | 1 | my $dec = Encoding::BER->new( ); | |||||||||
| 27 | 1 | $dec->add_tag('application', 'constructed', 'berdump_hash', 3); | |||||||||
| 28 | 1 | decanon($dec->decode($ber)); | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 9 | ▶ | sub decanon { | ||||||||
|
Subroutine
decanon: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 32 | 9 | my $n = shift; | |||||||||
| 33 | 9 | my $v = $n->{value}; | |||||||||
| 34 | |||||||||||
| 35 | 9 | ▶ | return $v unless ref $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | 2 | my @v; | |||||||||
| 38 | 2 | for my $r (@$v){ | |||||||||
| 39 | 8 | push @v, decanon($r); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 2 | ▶ | if( $n->{type}[2] eq 'berdump_hash' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 1 | return { @v }; | |||||||||
| 44 | }else{ | ||||||||||
| 45 | 1 | return \@v; | |||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||
| 50 | 1 | my $pkg = shift; | |||||||||
| 51 | 1 | my $caller = caller; | |||||||||
| 52 | |||||||||||
| 53 | 1 | for my $f ('pl2ber', 'ber2pl'){ | |||||||||
| 54 | 1 | ▶ | no strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 2 | my $fnc = $pkg->can($f); | |||||||||
| 56 | 2 | ▶ | next unless $fnc; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 2 | *{$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 | 1; | |||||||||