File: config_package.pm

package info (click to toggle)
config-package-dev 5.5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 632 kB
  • sloc: perl: 247; makefile: 66; sh: 49
file content (48 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl

package Debian::Debhelper::config_package;

use warnings;
use strict;

use Exporter;
use vars qw(@ISA @EXPORT);
@ISA=qw(Exporter);
@EXPORT=qw(&encode &decode);

sub encode {
    my $result = "";
    my $input = shift;
    $input =~ s,^/,,;
    foreach (split('', $input)) {
        if (m/[a-z0-9.-]/) {
            $result .= "$_";
        } elsif (m/[A-Z]/) {
            $result .= "+".lc($_)."+";
        } elsif ($_ eq '/') {
            $result .= "++";
        } elsif ($_ eq '_') {
            $result .= "+-+";
        } else{
            $result .= "+x".hex(ord($_))."+";
        }
    }
    return $result;
}

sub unparse {
    $_ = $_[0];
    return "/" unless $_;
    return "_" if $_ eq "-";
    return uc($_) if /^[a-z]$/;
    s/^x//;
    return chr hex $_;
}

sub decode {
    my $input = shift;
    $input =~ s/\+([^+]*)\+/unparse($1)/eg;
    return $input;
}

1