| File: | blib/lib/Simba/Util.pm |
| Coverage: | 86.1% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/perl | ||||||
| 2 | package Simba::Util; | ||||||
| 3 | |||||||
| 4 | 3 3 3 | 19 3 113 | use warnings; | ||||
| 5 | 3 3 3 | 12 3 79 | use strict; | ||||
| 6 | 3 3 3 | 11 4 87 | use Exporter qw( import ); | ||||
| 7 | 3 3 3 | 11 3 881 | use Encode qw(decode encode ); | ||||
| 8 | |||||||
| 9 | our @EXPORT_OK = qw(quote unquote typestr); | ||||||
| 10 | |||||||
| 11 | sub quote { | ||||||
| 12 | 96 | 0 | 330 | my ($s) = @_; | |||
| 13 | 96 8 | 180 73 | $s =~ s{[\000-\040&=]}{sprintf("&#%d;", ord($&))}eg; | ||||
| 14 | 96 | 1051 | return encode('utf-8', $s); | ||||
| 15 | } | ||||||
| 16 | |||||||
| 17 | sub unquote { | ||||||
| 18 | 2 | 0 | 4 | my ($s) = @_; | |||
| 19 | 2 | 26 | $s = decode('utf-8', $s); | ||||
| 20 | 2 0 | 192 0 | $s =~ s{&#(\d+);}{chr($1)}eg; | ||||
| 21 | 2 | 24 | return $s; | ||||
| 22 | } | ||||||
| 23 | |||||||
| 24 | my @typestr = ( | ||||||
| 25 | #0 1 2 3 4 5 6 7 | ||||||
| 26 | '?', 'p', 'c', '?', 'd', '?', 'b', '?', | ||||||
| 27 | 'f', '?', 'l', '?', 's', '?', '?', '?', | ||||||
| 28 | ); | ||||||
| 29 | sub typestr { | ||||||
| 30 | 50 | 0 | 111 | my ($mode) = @_; | |||
| 31 | 50 | 46 | $mode >>= 12; | ||||
| 32 | 50 | 808 | return $typestr[$mode] || '?'; | ||||
| 33 | } | ||||||
| 34 | |||||||
| 35 | 1; | ||||||