NAME

Hub::Parse::Transform -

Part of the Hub Library

SYNOPSIS

DESCRIPTION

METHODS

Xpopulate findAbsolutePath getspec nbspstr safestr
abspath fixpath hashtoattrs packcgi siteurl
attrhash fw html polish trimcss
datetime getext indenttext populate trimhtmlstyle
dhms getname jsstr ps unpackcgi
fcols getpath mkabsdir relpath
Xpopulate

abspath

Usage: abspath PATH
Usage: abspath PATH NOCHECK

File must exist unless NOCHECK is specified.

attrhash

datetime

Usage: datetime TIMESTAMP?, OPTION*

Friendly date-time formats of seconds-since-the-epoch timestamps.

Default is the current time formatted as: MM/DD/YYYY hh:mm:ss.

The decimal portion of HiRest time is truncated.

Uses `localtime` to localize.

This example returns: true:

datetime( );

Example: This example:

datetime( 1045837284 );

matches:

02/21/2003 06:21:24

Example: This example:

datetime( 1045837284, -nosec );

matches:

02/21/2003 06:21

Example: This example:

datetime( 1045837284, -noyear );

matches:

02/21 06:21:24

Example: This example:

datetime( 1045837284, -ampm );

matches:

02/21/2003 06:21:24am

Example: This example:

datetime( 1045837284, -nozeros );

matches:

2/21/2003 6:21:24

Example: This example:

datetime( 1045837284, -notime );

matches:

02/21/2003

Example: This example:

datetime( 1045837284, -nodate );

matches:

06:21:24

Example: This example:

datetime( 1045837284, -letter );

matches:

February 21, 2003 06:21:24

Combining options

Example: This example:

datetime( 1045837284, -ampm, -nosec );              

matches:

02/21/2003 06:21am

Example: This example:

datetime( 1045837284, -nosec, -nozeros, -noyear );

matches:

2/21 6:21

Methods of passing options via tweaks (see Parser.pm)

Example: This example:

datetime( 1045837284, "nosec,noyear" );

matches:

02/21 06:21
dhms

Hub::dhms( $seconds, $options, $format )

Format the provided number of seconds in days, hours, minutes, and seconds.

Examples:                                               Returns:
------------------------------------------------------- --------------------
Hub::dhms( 10 )                                              00d:00h:00m:10s
Hub::dhms( 60 )                                              00d:00h:01m:00s
Hub::dhms( 3600 )                                            00d:01h:00m:00s
Hub::dhms( 86400 )                                           01d:00h:00m:00s
Hub::dhms( 11 )                                              00d:00h:00m:11s
Hub::dhms( 71 )                                              00d:00h:01m:11s
Hub::dhms( 3671 )                                            00d:01h:01m:11s
Hub::dhms( 90071 )                                           01d:01h:01m:11s
Hub::dhms( 90071, "--nozeros" )                              1d:1h:1m:11s
Hub::dhms( 90071, "--nozeros" )                              1d:1h:1m:11s
Hub::dhms( 90071, "--nozeros", "days ::" )   1days 1:1:11
Hub::dhms( 90071, "days ::" )                01days 01:01:11
fcols

Usage: fcols STRING, COLS, [OPTIONS]

Divide text into fixed-width columns.

Where OPTIONS can be:

--split:REGEX                   # Split on regex REGEX (default '\s')
--flow:ttb|ltr                  # Top-to-bottom or Left-to-right (default 'ttb')
--pad:NUM                       # Spacing between columns (default 1)
--padwith:STR                   # Pad with STR (multiplied by --pad)
--width:NUM                     # Force column width (--pad becomes irrelevant)
--justify:left|center|right     # Justify within column

Examples:

1) print fcols( "A B C D E F G", 4, "-flow=ttb" ), "\n";


    A C E G
    B D F


2) print fcols( "a b c d e f g", 4, "-flow=ltr" ), "\n";


    a b c d
    e f g
findAbsolutePath

findAbsolutePath( "../usr/" )
findAbsolutePath( "/usr/local" )


File may or may not exist
fixpath

Usage: fixpath( $path )

Clean up malformed paths (usually do to concatenation logic).

Example: This example:

fixpath( "../../../users/newuser/web/bin/../src/screens" );

matches:

../../../users/newuser/web/src/screens

Example: This example:

fixpath( "users/newuser/web/" );

matches:

users/newuser/web

Example: This example:

fixpath( "users/../web/bin/../src" );

matches:

web/src

Example: This example:

fixpath( "users//newuser" );

matches:

users/newuser

Example: This example:

fixpath( "users//newuser/./files" );

matches:

users/newuser/files

Example: This example:

fixpath( "http://site/users//newuser" );

matches:

http://site/users/newuser

Example: This example:

fixpath( '/home/hub/build/../../../out/doc/pod' );

matches:

/out/doc/pod
fw

fixed-width (default padding is a space)

Warning, many calls to this method is a performance hit!

usage examples:

Hub::fw( 5, "Hello World" )                  "Hello"
Hub::fw( 5, "Hello World", '-clip=0' )       "Hello world"
Hub::fw( 5, "Hi" )                           "Hi   "
Hub::fw( 5, "Hi", '-align=r' )               "   Hi"
Hub::fw( 5, "Hi", '-align=l' )               "Hi   "
Hub::fw( 5, "Hi", '-align=c' )               "  Hi "
Hub::fw( 5, "Hi", '-repeat' )                "HHHHH"
Hub::fw( 5, "Hi", '-pad=x' )                 "Hixxx"
Hub::fw( 5, "Hi", '-pad=x', '-align=r' )     "xxxHi"


Depricated:


Hub::fw( 5, "Hi", "right" )                  "   Hi"
Hub::fw( 5, "Hi", "repeat" )                 "HHHHH"
Hub::fw( 5, "Hi", "padding:x" )              "Hixxx"
Hub::fw( 5, "Hi", "padding:x", "right" )     "xxxHi"
getext

getext( $path )


example:


    getext( "/foo/bar/filename.ext" )
    getext( "filename.cgi" )


will return:


    "ext"
    "cgi"
getname

getname( $path )


Note, if the given path is a full directory path, the last directory is
still considerred a filename.



example:


    getname( "../../../users/newuser/web/data/p001/batman-small.jpg" );
    getname( "../../../users/newuser/web/data/p001" );
    getname( "/var/log/*.log" );


will return:


    "batman-small.jpg"
    "p001"
    "*.log"
getpath

Exract the parent from the given filepath


for example:


    getpath( "/etc/passwd" )        /etc
    getpath( "/usr/local/bin" )     /usr/local
getspec

Usage: getspec PATH

Given a path to a file, return it's parts (directory, filename, extension);

hashtoattrs

Usage: hashtoattrs

Turn the given hash into an key="value" string.

{
    'class'     => "foodidly",
    'name'      => "bobsmith",
    'height'    => "5px",
}

Becomes:

class="foodidly" name="bobsmith" height="5px"
html

Format a string, replacing spaces with ' '


for example:


    html( "<Hello=world!>" )              "&lt;Hello=World&gt;"
indenttext

Usage: indenttext TEXT, NUM, [PADINGCHAR]

Indent text

jsstr

Usage: jsstr

Format as one long string for use as the rval in javascript (ie put the backslash continue-ator at the end of each line).

mkabsdir

Usage: mkabsdir DIR

Create the directory specified.

nbspstr

Format a string, replacing spaces with '&nbsp;'


for example:


    nbspstr( "Hello <not html tags> world!" )


would return:


    "Hello&nbsp;<not html tags>&nbsp;World"
packcgi

Usage: packcgi STRING

Pack characters into those used for passing by the cgi.

polish

Remove undefined variables

populate

Usage: populate TEXT, DEFINITIONS+

Depricated.

Populate TEXT with DEFINITIONS.

ps

Usage: ps

Aka: Proportional Space

Split the given string up into multiple lines which will not exceed the specified character width.

Default padding is a space.

Example: This example:

ps( 10, "this is really short but splits on ten chars" );

matches:

   this is re
   ally short
but split
   s on ten c
   hars

Example: This example:

ps( 10, "this is really short but splits on ten chars", 3 );

matches:

 this is re
ally short
 but split
s on ten c
hars
relpath

Relative path

Usage: relpath PATH, FROMPATH

OPTIONS:

-asdir      Specifies that FROMPATH is a directory.  Provided for times when
            FROMPATH does not exist (and hence the -d test will fail).

Return the path to PATH from FROMPATH.

Example: This example:

relpath( "/home/docs", "/home/docs/install", -asdir );

matches:

..

Example: This example:

relpath( "/home/docs", "/home/docs/README.txt" );

matches:

.

Example: This example:

relpath( "/home/src", "/home/docs/install", -asdir );

matches:

../../src

Example: This example:

relpath( "/home/docs/README.txt", "/home/docs", -asdir );

matches:

README.txt
safestr

Usage: safestr STRING

Pack nogood characters into good ones. Good characters are letters, numbers, and the underscore.

Example: This example:

safestr( 'Dogs (Waters, Gilmour) 17:06' );

matches:

Dogs_20__28_Waters_2c__20_Gilmour_29__20_17_3a_06
siteurl

Usage: siteurl

Return the target website url.

trimcss

Usage: trimcss

Remove empty css properties

trimhtmlstyle

Usage: trimhtmlstyle

Remove empty style declarations

unpackcgi

Usage: unpackcgi QUERY

Unpack cgi characters into a kv hashref

INTERNAL

_runTweaks
_runTweaks

Standard tweaks

Tweaks allow modification to variable values without modifying the original.

No spaces are allowed in the tweak!

Implemented tweaks:

tr///               # transliterates search chars with replacement chars
lc                  # lower case
uc                  # upper case
lcfirst             # lower case first letter
ucfirst             # upper case first letter
x=                  # repeat the value so many times
nbspstr             # replace spaces with non-breaking ones
html                # replace '<' and '>' with '&lt;' and '&gt;'
jsstr               # escape quotes and end-of-lines with a backslash
num                 # number (will use zero '0' if empty)
dt(opts)            # datetime with options (see datetime).

Hub::dhms(opts)     # day/hour/min/sec with options (see dhms).



eq                  # equal
ne                  # not equal
gt                  # greater than
lt                  # less than
if                  # is greater than zero (or non-empty string)


-                   # minus
+                   # plus
*                   # multiply
/                   # divide
%                   # mod


darker(num)         # makes a color darker (default num=0xA)
lighter(num)        # makes a color lighter (default num=0xA)
rotate_base         # rotates bases (red -> green, green -> blue, blue -> red)
inverse             # invert color (like red becomes cyan)

Examples:

        # if v is 'HELLO', it becomes 'hello'
       # if v is '.', it becomes '.....'
   # the value for 'v' is printed when 1 is equal to 2
   # the value for 'v' is printed when 1 isn't equal to 2
     # the value for 'v' is printed when it is equal to 2
# if v is 's' and c is greater than one, 's' is printed

Tweaks can be chained together, for example:

   # if v is "HELLO", it becomes 'Hello'
# if v is "hello" and c is greater than 1, it becomes 'HELLO'

AUTHOR

Ryan Gies

COPYRIGHT

Copyright (c) 2006 Livesite Networks, LLC. All rights reserved.

Copyright (c) 2000-2005 Ryan Gies. All rights reserved.

UPDATED

This file created by mkdocs.pl on 8/29/2006 at 2:07pm