XML::Filter::XML_Directory_2XHTML - SAX2 filter for munging XML::Directory::SAX output into XHTML
use strict; package MySAX; use base qw (XML::SAX::Base); use Image::Magick; sub parse_uri { my $self = shift; my $uri = shift; my $magick = Image::Magick->new(); if (my $err = $magick->Read($uri)) { carp $err; return 0; } if (my $comment = $magick->Get("comment")) { $self->SUPER::start_element({Name=>"p"}); $self->SUPER::characters({Data=>$comment}); $self->SUPER::end_element({Name=>"p"}); } return 1; } package main; use IO::File; use XML::SAX::Writer; use XML::Directory::SAX; use XML::Filter::XML_Directory_2XHTML; my $file = IO::File->new(">/htdocs/INC-0.html"); my $writer = XML::SAX::Writer->new(Output=>$file); my $filter = XML::Filter::XML_Directory_2XHTML->new(Handler=>$writer); # Define some images to associate with directory listing. $filter->set_images({ # Some defaults directory => {src=>"/icons/dir.gif",height=>20,width=>20}, file => {src=>"/icons/unknown.gif",height=>20,width=>20}, # An image for a file whose media type # as defined by MIME::Types is 'image'. # This is the case for .pl and .pm files image => {src=>"/icons/image3.gif",height=>20,width=>20}, }); # This package inherits from XML::Filter::XML_Directory_2::Base # which defines a framework for defining event based callbacks # and handlers. $filter->set_callbacks({ link => sub { return "file://".$_[0]; }, # This is not the greatest example because # this is actually what the linktext is set # to if no 'linktext' callback or handler is # defined but you get the idea. linktext => sub { return &basename($_[0]); }, title => sub { return "woot woot woot"; }, }); $filter->set_handlers({ file => MySAX::File->new(Handler=>$writer), }); # In turn, XML::Filter::XML_Directory_2::Base inherits from # XML::Filter::XML_Directory_Pruner which provides hooks for # restricting the output of XML::Directory::SAX $filter->exclude(exclude=>["CVS"]); my $directory = XML::Directory::SAX->new(depth=>0,detail=>2,Handler=>$filter); $directory->order_by("a"); $directory->parse_dir($INC[0]);
SAX2 filter for munging XML::Directory::SAX output into XHTML.
This package allows for the following event callbacks and/or handlers to be registered:
Since this functionaliy is inherited from XML::Filter::XML_Directory_2::Base, please consult the documentation for that package for details.
linktext
Modify the linktext for the current document. The default value is the filename itself.
file
Define additional output to follow the name of the current file.
directory
Define additional output to follow the name of the current directory.
link
Modify the value of the HTML a@href attribute for the current document. The default value is the absolute path of the document itself.
title
Set the value of the HTML <title> element for your document. The default is the absolute path of the directory you are parsing.
Each directory and file in the XML::Directory output is wrapped in HTML <div> elements. Each element is assigned a class attributes whose name matches the type of file, either a file or directory.
The default CSS styles for those classes are :
.file { border:1px dotted #ccc; margin-left:10px; margin-bottom:5px; margin-top:5px; padding-right:50px; } .directory { border:1px dotted #666; margin-left:10px; margin-bottom:10px; }
They can be altered by passing a user-defined CSS stylesheet via the filter's set_styles object method.
Object constructor. Returns an object. Woot!
Define image files to be included with a file or a directory.
Valid arguments are a hash ref whose key may be :
string - the value returned by the MIME::Types::mediaType function for a document.
Each key defines it own hash reference whose keys are :
src
String. Required.
height
Int. Required.
width
alt
String.
Define additional stylesheets for your document.
Valid arguments are an array reference of hash reference. Each hash ref may contain the following keys:
href
rel
String. Default is "stylesheet"
media
String. Default is "all"
Define scripts for your document.
Please consults the docs for XML::Filter::XML_Directory_2::Base for details
1.0
July 02, 2002
Aaron Straup Cope
Add hooks to set <meta> tags
Add hooks to set <link> tags
Add hooks to set <html@lang> attribute
XML::Filter::XML_Directory_2::Base
XML::Directory::SAX
Copyright (c) 2002, Aaron Straup Cope. All Rights Reserved.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install XML::Filter::XML_Directory_2XHTML, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Filter::XML_Directory_2XHTML
CPAN shell
perl -MCPAN -e shell install XML::Filter::XML_Directory_2XHTML
For more information on module installation, please visit the detailed CPAN module installation guide.