Marc Lehmann > PApp > PApp::Util

Download:
PApp-2.0.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 2   Source  

NAME ^

PApp::Util - various utility functions that didn't fit anywhere else

SYNOPSIS ^

   use PApp::Util;

DESCRIPTION ^

This module offers various utility functions that cannot be grouped into other categories easily.

format_source $source

Formats a file supposed to be some "sourcecode" (e.g. perl, papp, xslt etc..) into formatted ascii. It includes line numbering at the front of each line and handles embedded "#line" markers.

dumpval any-perl-ref

Tries to dump the given perl-ref into a nicely-formatted human-readable-format (currently uses either Data::Dumper or Dumpvalue) but tries to be very robust about internal errors, i.e. this functions always tries to output as much usable data as possible without die'ing.

$ref = decode_json $json

Converts a JSON string into the corresponding perl data structure.

$json = encode_json $ref

Converts a perl data structure into its JSON representation.

digest(args...)

Calculate a SHA1 digest and return it base64-encoded. The result will always be 27 characters long.

append_string_hash $hashref1, $hashref2

Appends all the strings found in $hashref2 to the respective keys in $hashref1 (e.g. $h1->{key} .= $h2->{key} for all keys).

@ = uniq @array

Returns all the elements that are unique inside the array. The elements must be strings, or at least must stringify sensibly.

sv_peek $sv
sv_dump $sv

Returns a very verbose dump of the internals of the given sv. Calls the sv_peek (sv_dump) core function. If you don't know what I am talking about then this function is not for you. Or maybe you should try it.

fetch_uri $uri

Tries to fetch the document specified by $uri, returning undef on error. As a special "goody", uri's of the form "data:,body" will immediately return the body part.

find_file $uri [, \@extensions] [, @bases]

Try to locate the specified document. If the uri is a relative uri (or a simple unix path) it will use the URIs in @bases and PApp's search path to locate the file. If bases contain an arrayref than this arrayref should contain a list of extensions (without a leading dot) to append to the URI while searching the file.

load_file $uri [, @extensions]

Locate the document specified by the given uri using find_file, then fetch and return it's contents using fetch_uri.

mime_header $text

Takes text and transforms it to a mime message header suitable for message headers. If the text is US-ASCII it will be returned unchanged, otherwise it will be encoded according to RFC 2047 (it will be split into multiple CRLF-Tab-separated components of no longer than 75 characters, with the first component not be longer than 40 characters).

ntoa $bin
aton $text

Same as inet_ntoa/inet_aton, but works on (numerical) IPv4 and IPv6 addresses.

ipv6 not yte implemented

Source Filtering

A very primitive form of source filtering can be implemented using filter_add, filter_read and filter_simple. Better use the Filter module family, though.

nonce $octet_count

Return a nonce suitable for cryptographically.

alnumbits $octets

Convert the given octet string into a human-readable ascii text, using only a-zA-Z0-9 characters (base62 encoding).

SEE ALSO ^

PApp.

AUTHOR ^

 Marc Lehmann <schmorp@schmorp.de>
 http://home.schmorp.de/
syntax highlighting: