To export a function, add it to the 'use' call.
use HTML::LinkList qw(link_list);
To export all functions do:
use HTML::LinkList ':all';
link_list
$links = link_list(
current_url=>$url,
urls=>\@links_in_order,
labels=>\%labels,
descriptions=>\%desc,
pre_desc=>' ',
post_desc=>'',
links_head=>'<ul>',
links_foot=>'</ul>',
pre_item=>'<li>',
post_item=>'</li>'
pre_active_item=>'<em>',
post_active_item=>'</em>',
item_sep=>"\n");
Generates a simple list of links, from list of urls (and optional labels) taking into account of the
"current" URL.
This provides a large number of options to customize the appearance of the list. The default setup is
for a simple UL list, but setting the options can enable you to make it something other than a list
altogether, or add in CSS styles or classes to make it look just like you want.
Required:
urls
The urls in the order you want them displayed. If this list is empty, then nothing will be
generated.
Options:
current_url
The link to the current page. If one of the links equals this, then that is deemed to be the
"active" link and is just displayed as a label rather than a link.
descriptions
Optional hash of descriptions, to put next to the links. The keys of this hash are the urls.
hide_ext
If a site is hiding link extensions (such as using MultiViews with Apache) you may wish to hide the
extensions (while using the full URLs to check various things). (default: 0 (false))
item_sep
String to put between items.
labels
A hash whose keys are links and whose values are labels. These are the labels for the links; if no
label is given, then the last part of the link is used for the label, with some formatting.
links_head
String to begin the list with.
links_foot
String to end the list with.
pre_desc
String to prepend to each description.
post_desc
String to append to each description.
pre_item
String to prepend to each item.
post_item
String to append to each item.
pre_active_item
An additional string to put in front of each "active" item, after pre_item. The "active" item is the
link which matches 'current_url'.
pre_item_active
INSTEAD of the "pre_item" string, use this string for active items
post_active_item
An additional string to append to each active item, before post_item.
prefix_url
A prefix to prepend to all the links. (default: empty string)
link_tree
$links = link_tree(
current_url=>$url,
link_tree=>\@list_of_lists,
labels=>\%labels,
descriptions=>\%desc,
pre_desc=>' ',
post_desc=>'',
links_head=>'<ul>',
links_foot=>'</ul>',
subtree_head=>'<ul>',
subtree_foot=>'</ul>',
pre_item=>'<li>',
post_item=>'</li>'
pre_active_item=>'<em>',
post_active_item=>'</em>',
item_sep=>"\n",
tree_sep=>"\n",
formats=>\%formats);
Generates nested lists of links from a list of lists of links. This is useful for things such as table-
of-contents or site maps.
By default, this will return UL lists, but this is highly configurable.
Required:
link_tree
A list of lists of urls, in the order you want them displayed. If a url is not in this list, it will
not be displayed.
Options:
current_url
The link to the current page. If one of the links equals this, then that is deemed to be the
"active" link and is just displayed as a label rather than a link.
descriptions
Optional hash of descriptions, to put next to the links. The keys of this hash are the urls.
exclude_root_parent
If this is true, then the "current_parent" display options are not used for the "root" ("/") path, it
isn't counted as a "parent" of the current_url.
formats
A reference to a hash containing advanced format settings. For example:
my %formats = (
# level 1 and onwards
'1' => {
tree_head=>"<ol>",
tree_foot=>"</ol>\n",
},
# level 2 and onwards
'2' => {
tree_head=>"<ul>",
tree_foot=>"</ul>\n",
},
# level 3 and onwards
'3' => {
pre_item=>'(',
post_item=>')',
item_sep=>",\n",
tree_sep=>' -> ',
tree_head=>"<br/>\n",
tree_foot=>"",
}
);
The formats hash enables you to control the formatting on a per-level basis. Each key of the hash
corresponds to a level-number; the sub-hashes contain format arguments which will apply from that
level onwards. If an argument isn't given in the sub-hash, then it will fall back to the previous
level (or to the default, if there is no setting for that format-argument for a previous level).
The only difference between the names of the arguments in the sub-hash and in the global format
arguments is that instead of 'subtree_head' and subtree_foot' it uses 'tree_head' and 'tree_foot'.
hide_ext
If a site is hiding link extensions (such as using MultiViews with Apache) you may wish to hide the
extensions (while using the full URLs to check various things). (default: 0 (false))
item_sep
The string to separate each item.
labels
A hash whose keys are links and whose values are labels. These are the labels for the links; if no
label is given, then the last part of the link is used for the label, with some formatting.
links_head
The string to prepend the top-level tree with. (default: <ul>)
links_foot
The string to append to the top-level tree. (default: </ul>)
pre_desc
String to prepend to each description.
post_desc
String to append to each description.
pre_item
String to prepend to each item. (default: <li>)
post_item
String to append to each item. (default: </li>)
pre_active_item
An additional string to put in front of each "active" item, after pre_item. The "active" item is the
link which matches 'current_url'. (default: <em>)
pre_item_active
INSTEAD of the "pre_item" string, use this string for active items
post_active_item
An additional string to append to each active item, before post_item. (default: </em>)
pre_current_parent
An additional string to put in front of a link which is a parent of the 'current_url' link, after
pre_item.
pre_item_current_parent
INSTEAD of the "pre_item" string, use this for links which are parents of the 'current_url' link.
post_current_parent
An additional string to append to a link which is a parent of the 'current_url' link, before
post_item.
prefix_url
A prefix to prepend to all the links. (default: empty string)
subtree_head
The string to prepend to lower-level trees. (default: <ul>)
subtree_foot
The string to append to lower-level trees. (default: </ul>)
tree_sep
The string to separate each tree.
full_tree
$links = full_tree(
paths=>\@list_of_paths,
labels=>\%labels,
descriptions=>\%desc,
hide=>$hide_regex,
nohide=>$nohide_regex,
start_depth=>0,
end_depth=>0,
top_level=>0,
preserve_order=>0,
preserve_paths=>0,
...
);
Given a set of paths this will generate a tree of links in the style of link_tree. This will figure out
all the intermediate paths and construct the nested structure for you, clustering parents and children
together.
The formatting options are as for "link_tree".
Required:
paths
A reference to a list of paths: that is, URLs relative to the top of the site.
For example, if the full URL is http://www.example.com/foo.html then the path is /foo.html
If the full URL is http://www.example.com/~frednurk/foo.html then the path is /foo.html
This does not require that every possible path be given; all the intermediate paths will be figured
out from the list.
Options:
append_list
Array of paths to append to the top-level links. They are used as-is, and are not part of the
processing done to the "paths" list of paths. (see "prepend_list")
descriptions
Optional hash of descriptions, to put next to the links. The keys of this hash are the paths.
end_depth
End your tree at this depth. If zero, then go all the way. (see "start_depth")
exclude_root_parent
If this is true, then the "current_parent" display options are not used for the "root" ("/") path, it
isn't counted as a "parent" of the current_url.
hide
If the path matches this string, don't include it in the tree.
hide_ext
If a site is hiding link extensions (such as using MultiViews with Apache) you may wish to hide the
extensions (while using the full URLs to check various things). (default: 0 (false))
labels
Hash containing replacement labels for one or more paths. If no label is given for '/' (the root
path) then 'Home' will be used.
last_subtree_head
The string to prepend to the last lower-level tree. Only used if end_depth is not zero.
last_subtree_foot
The string to append to the last lower-level tree. Only used if end_depth is not zero.
nohide
If the path matches this string, it will be included even if it matches the 'hide' string.
prefix_url
A prefix to prepend to all the links. (default: empty string)
prepend_list
Array of paths to prepend to the top-level links. They are used as-is, and are not part of the
processing done to the "paths" list of paths.
preserve_order
Preserve the ordering of the paths in the input list of paths; otherwise the links will be sorted
alphabetically. Note that if preserve_order is true, the structure is at the whims of the order of
the original list of paths, and so could end up odd-looking. (default: false)
preserve_paths
Do not extract intermediate paths or reorder the input list of paths. This speeds things up, but
assumes that the input paths are complete and in good order. (default: false)
start_depth
Start your tree at this depth. Zero is the root, level 1 is the files/sub-folders in the root, and
so on. (default: 0)
top_level
Decide which level is the "top" level. Useful when you set the start_depth to something greater than
1.
breadcrumb_trail
$links = breadcrumb_trail(
current_url=>$url,
labels=>\%labels,
descriptions=>\%desc,
links_head=>'<p>',
links_foot=>"\n</p>",
subtree_head=>'',
subtree_foot=>"\n",
pre_item=>'',
post_item=>'',
pre_active_item=>'<em>',
post_active_item=>'</em>',
item_sep=>"\n",
tree_sep=>' > ',
...
);
Given the current url, make a breadcrumb trail from it. By default, this is laid out with '>'
separators, but it can be set up to give a nested set of UL lists (as for "full_tree").
The formatting options are as for "link_tree".
Required:
current_url
The current url to be made into a breadcrumb-trail.
Options:
descriptions
Optional hash of descriptions, to put next to the links. The keys of this hash are the urls.
exclude_root_parent
If this is true, then the "current_parent" display options are not used for the "root" ("/") path, it
isn't counted as a "parent" of the current_url.
hide_ext
If a site is hiding link extensions (such as using MultiViews with Apache) you may wish to hide the
extensions (while using the full URLs to check various things). (default: 0 (false))
labels
Hash containing replacement labels for one or more URLS. If no label is given for '/' (the root
path) then 'Home' will be used.
nav_tree
$links = nav_tree(
paths=>\@list_of_paths,
labels=>\%labels,
current_url=>$url,
hide=>$hide_regex,
nohide=>$nohide_regex,
preserve_order=>1,
descriptions=>\%desc,
...
);
This takes a list of links, and the current URL, and makes a nested navigation tree, consisting of (a)
the top-level links (b) the links leading to the current URL (c) the links on the same level as the
current URL, (d) the related links just above this level, depending on whether this is an index-page or a
content page.
Optionally one can hide links which match match the 'hide' option.
The formatting options are as for "link_tree", with some additions.
Required:
current_url
The link to the current page. If one of the links equals this, then that is deemed to be the
"active" link and is just displayed as a label rather than a link. This is also used to determine
which links to show and which ones to filter out.
paths
A reference to a list of paths: that is, URLs relative to the top of the site.
For example, if the full URL is http://www.example.com/foo.html then the path is /foo.html
This does not require that every possible path be given; all the intermediate paths will be figured
out from the list.
Options:
append_list
Array of paths to append to the top-level links. They are used as-is, and are not part of the
processing done to the "paths" list of paths. (see "prepend_list")
descriptions
Optional hash of descriptions, to put next to the links. The keys of this hash are the paths.
end_depth
End your tree at this depth. If zero, then go all the way. By default this is set to the depth of
the current_url.
exclude_root_parent
If this is true, then the "current_parent" display options are not used for the "root" ("/") path, it
isn't counted as a "parent" of the current_url.
hide
If a path matches this string, don't include it in the tree.
hide_ext
If a site is hiding link extensions (such as using MultiViews with Apache) you may wish to hide the
extensions (while using the full URLs to check various things). (default: 0 (false))
labels
Hash containing replacement labels for one or more paths. If no label is given for '/' (the root
path) then 'Home' will be used.
last_subtree_head
The string to prepend to the last lower-level tree.
last_subtree_foot
The string to append to the last lower-level tree.
nohide
If the path matches this string, it will be included even if it matches the 'hide' string.
prefix_url
A prefix to prepend to all the links. (default: empty string)
prepend_list
Array of paths to prepend to the top-level links. They are used as-is, and are not part of the
processing done to the "paths" list of paths.
preserve_order
Preserve the ordering of the paths in the input list of paths; otherwise the links will be sorted
alphabetically. (default: true)
preserve_paths
Do not extract intermediate paths or reorder the input list of paths. This speeds things up, but
assumes that the input paths are complete and in good order. (default: false)
start_depth
Start your tree at this depth. Zero is the root, level 1 is the files/sub-folders in the root, and
so on. (default: 1)
top_level
Decide which level is the "top" level. Useful when you set the start_depth to something greater than
1.