sbase.pl man page on DragonFly

Man page or keyword search:  
man Server   44335 pages
apropos Keyword Search (all sections)
Output format
DragonFly logo
[printable version]

SBASE(1)	      User Contributed Perl Documentation	      SBASE(1)

NAME
	sbase - Create class which will provide access to HTML files as modules

SYNOPSIS
	sbase $DOCUMENT_ROOT/..

DESCRIPTION
       The first thing to never ever forget about HTML::Seamstress is this:

	There is no magick *anywhere*

       If you know object-oriented Perl and you are comfortable with
       conceptualizing HTML as a tree, then you can never get confused.
       Everything that Seamstress offers is based on improving the synergy of
       these two powers.

       So, let's look at one way to manipulate HTML, completely Seamstress-
       free:

	use HTML::TreeBuilder;
	my $tree = HTML::TreeBuilder->new_from_file('/usr/www/file.html');
	$tree->this;
	$tree->that;
	$tree->as_HTML;

       Let's make it easier to find "file.html":

	package www::file;
	use base qw(HTML::Seamstress);

	sub new {
	    HTML::TreeBuilder->new_from_file('/usr/www/file.html');
	}

       So now our code is this:

	use www::file;
	my $tree = www::file->new;
	$tree->this;
	$tree->that;
	$tree->as_HTML;

       Same amount of code. It's just we dont have to manage pathnames.

       Now, Seamstress actually does something a little more flexible in the
       package it creates for your class. Instead of a long absolute path, it
       abstracts away the root of the absolute path, creating a class for your
       HTML file like this:

	package www::file;
	use base qw(HTML::Seamstress::Base); # slight difference

	sub new {
	    HTML::TreeBuilder->new_from_file(
	      HTML::Seamstress::Base->comp_root() . 'file.html';
	  )
	}

       And the mainline code uses "www::file" just as before.

       So now we see some flexibility. The method
       "HTML::Seamstress::Base::comp_root()" can be configured to return
       values based on configuration settings and can vary based on deployment
       setup (e.g. production versus dev).

       So, sbase creates the "HTML::Seamstress::Base" package for you. It will
       work fine for most setups. If your root is not hardcoded and must be
       derived by a series of function calls, then simply modify "Base.pm" to
       fit your setup. Where I work, our Base class looks like this:

	package HTML::Seamstress::Base;
	use base qw(HTML::Seamstress);

	use Wigwam::Config;

	use vars     qw($comp_root);

	# put a "/" on end of path - VERY important
	BEGIN	      { $comp_root = $Wigwam::Config{'PLAYPEN_ROOT'} . '/' }

	use lib		$comp_root;

	sub comp_root { $comp_root }

	1;

       "Wigwam" is a tool for specifying all software and file path
       dependencies of your software: <http://www.wigwam-framework.com>. So,
       we get our

perl v5.20.2			  2015-09-15			      SBASE(1)
[top]

List of man pages available for DragonFly

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net