Hub::Parse::Transform -
Part of the Hub Library
Usage: abspath PATH Usage: abspath PATH NOCHECK
File must exist unless NOCHECK is specified.
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( );
This example returns: regex:
datetime( 1045837284 );
datetime( 1045837284, -nosec );
datetime( 1045837284, -noyear );
datetime( 1045837284, -ampm );
datetime( 1045837284, -nozeros );
datetime( 1045837284, -notime );
datetime( 1045837284, -nodate );
datetime( 1045837284, -letter );
Combining options
datetime( 1045837284, -ampm, -nosec );
datetime( 1045837284, -nosec, -nozeros, -noyear );
Methods of passing options via tweaks (see Parser.pm)
datetime( 1045837284, "nosec,noyear" );
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
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( "../usr/" ) findAbsolutePath( "/usr/local" ) File may or may not exist
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
fixpath( "users/newuser/web/" );
users/newuser/web
fixpath( "users/../web/bin/../src" );
web/src
fixpath( "users//newuser" );
users/newuser
fixpath( "users//newuser/./files" );
users/newuser/files
fixpath( "http://site/users//newuser" );
http://site/users/newuser
fixpath( '/home/hub/build/../../../out/doc/pod' );
/out/doc/pod
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( $path ) example: getext( "/foo/bar/filename.ext" ) getext( "filename.cgi" ) will return: "ext" "cgi"
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"
Exract the parent from the given filepath for example: getpath( "/etc/passwd" ) /etc getpath( "/usr/local/bin" ) /usr/local
Usage: getspec PATH
Given a path to a file, return it's parts (directory, filename, extension);
Usage: hashtoattrs
Turn the given hash into an key="value" string.
{ 'class' => "foodidly", 'name' => "bobsmith", 'height' => "5px", }
Becomes:
class="foodidly" name="bobsmith" height="5px"
Format a string, replacing spaces with ' ' for example: html( "<Hello=world!>" ) "<Hello=World>"
Usage: indenttext TEXT, NUM, [PADINGCHAR]
Indent text
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).
Usage: mkabsdir DIR
Create the directory specified.
Format a string, replacing spaces with ' ' for example: nbspstr( "Hello <not html tags> world!" ) would return: "Hello <not html tags> World"
Usage: packcgi $string|\$string
Pack characters into those used for passing by the cgi.
Remove undefined variables
We will chomp lines so that:
In between two lines with text or when surrounded spaced out..
Will become:
Populate template text with values
Usage: populate $text|\$text, \%values [,\%values...] [option]
options:
-sdref=0 Turn off scalar dereferencing -polish=1 Remove unpopulated variable references
populate( 'mum', { foo => 'shroo' } );
mushroom
ref( populate( 'ac', { b => 'bee' }, '-sdref=0' ) );
SCALAR
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.
ps( 10, "this is really short but splits on ten chars" );
this is re ally short but split s on ten c hars
ps( 10, "this is really short but splits on ten chars", 3 );
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.
relpath( "/home/docs", "/home/docs/install", -asdir );
..
relpath( "/home/docs", "/home/docs/README.txt" );
.
relpath( "/home/src", "/home/docs/install", -asdir );
../../src
relpath( "/home/docs/README.txt", "/home/docs", -asdir );
README.txt
Usage: safestr STRING
Pack nogood characters into good ones. Good characters are letters, numbers, and the underscore.
safestr( 'Dogs (Waters, Gilmour) 17:06' );
Dogs_20__28_Waters_2c__20_Gilmour_29__20_17_3a_06
Usage: siteurl
Return the target website url.
Usage: trimcss
Remove empty css properties
Usage: trimhtmlstyle
Remove empty style declarations
Usage: unpackcgi QUERY
Unpack cgi characters into a kv hashref
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 '<' and '>' 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)
# 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'
Ryan Gies
Copyright (c) 2006 Livesite Networks, LLC. All rights reserved.
Copyright (c) 2000-2005 Ryan Gies. All rights reserved.
This file created by on at
To install Hub, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hub
CPAN shell
perl -MCPAN -e shell install Hub
For more information on module installation, please visit the detailed CPAN module installation guide.