NAME

Bric::Util::Burner - Publishes Business Assets and Deploys Templates

VERSION

$LastChangedRevision$

DATE

$LastChangedDate: 2006-06-13 12:19:37 -0700 (Tue, 13 Jun 2006) $

SYNOPSIS

use Bric::Util::Burner qw(:modes);

# Create a new publish object.
$burner = new Bric::Util::Burner;

# Deploy a formatting asset.
$burner = $burner->deploy($formatting_asset);

# Undeploy a formatting asset.
$burner = $burner->undeploy($formatting_asset);

# Burn an asset given an output chanels and category
$burner->burn_one($asset, $output_channel, $category);

# set list of page extensions
$burner->set_page_extensions(@page_extensions);

# get list of page extensions
@page_extensions = $burner->get_page_extensions();

# set page numbering start
$burner->set_page_numb_start($start);

# retrieve page numbering start
$page_numb_start = burner->get_page_numb_start;

DESCRIPTION

This module accomplishes two tasks:

  1. Manages the process of deploying and undeploying of formatting assets through deploy() and undeploy().

  2. Manages the process of publishing and previewing business assets via the publish() and preview() methods, respectively. The actual work of publishing is done by one of Bric::Util::Burner's subclasses depending on the burner_type of the asset being published. See Bric::Util::Burner::Mason and Bric::Util::Burner::Template for details.

ADDING A NEW BURNER

We anticipate that new Burner subclasses will be added to the system. Here's a brief guide to adding a new Burner to Bricolage:

INTERFACE

In addition to the class and object methods documented below, Bric::Util::Burner can export a number of constants. These constants are used for comparing the values stored in the mode property of a burner object. They can be imported individually, or by using the :modes or :all export tags. The supported constants are:

PUBLISH_MODE

The burner object is in the process of publishing an asset.

PREVIEW_MODE

The burner object is in the process of previewing an asset.

SYNTAX_MODE

The burner object is in the process of checking the syntax of a template.

Constructors

$obj = new Bric::Util::Burner($init);

Creates a new burner object. The parameters that can be passed via the $init hash reference are:

data_dir

The directory where the Burner stores compiled template files. Defaults to the value stored in the BURN_DATA_ROOT directive set in bricolage.conf.

user_id

ID of the user to get a sandbox to deploy/undeploy templates for previewing. sandbox_dir is set from this value.

comp_dir

The directory to which the burner deploys and can find templates for burning. Defaults to the value stored in the BURN_COMP_ROOT directive set in bricolage.conf.

out_dir

The directory in which the burner writes burned content files upon publication or preview. Defaults to the value stored in the BURN_DATA_ROOT directive set in bricolage.conf.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Destructors

$self->DESTROY

Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

Public Class Methods

my $burner_class = Bric::Util::Burner->class_for_ext($ext);

Returns the name of the burner class that handles templates with the extension passed in. The extension must be the full extension name without with the ".", such as "mc" or "tmpl".

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $burner_class = Bric::Util::Burner->class_for_cat_fn($filename);

Returns the name of the burner class that handles category templates with the base file name passed in. The file name must be the base file name, omitting any exception, such as "autohandler" or "category".

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $burner_class = Bric::Util::Burner->cat_fn_has_ext($filename);

Returns true if the category template with the base file name $filename has a file extension, and false if it doesn't. For example Mason category templates have no extension, so this method returns false for the $filename "autohandler". On the other hand, HTML::Template templates do have extensions, so this method returns true for the $filename "category".

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $file_types = Bric::Util::Burner->list_file_types

Returns an array reference of array references of burner file name extensions mapped to labels for each. Suitable for use in select widgets.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Public Instance Methods

my $data_dir = $burner->get_data_dir

Returns the data directory.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$b = $burner->set_data_dir($data_dir)

Sets the data directory.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $comp_dir = $burner->get_comp_dir

Returns the component directory.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$b = $burner->set_comp_dir($comp_dir)

Sets the component directory.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $out_dir = $burner->get_out_dir

Returns the output directory.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$b = $burner->set_out_dir($out_dir)

Sets the output directory.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $mode = $burner->get_mode

Returns the burn mode. The value is an integer corresponding to one of the following constants: "PUBLISH_MODE", "PREVIEW_MODE", and "SYNTAX_MODE".

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $encoding = $burner->get_encoding

Returns the character set encoding to be used to write out the contents of a burn to a file. Defaults to "utf8".

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$b = $burner->set_encoding($encoding)

Sets the character set encoding to be used to write out the contents of a burn to a file under Perl 5.8.0 and later. Use this attribute if templates are converting output data from Bricolage's native UTF-8 encoding to another encoding. Use "raw" if your templates are outputting binary data. Defaults to "utf8".

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $story = $burner->get_story

Returns the story currently being burned -- that is, during the execution of templates by burn_one().

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $story = $burner->get_element

Returns the element currently being burned -- that is, during the execution of the various element templates by burn_one().

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $oc = $burner->get_oc

Returns the output channel in which the story returned by get_story() is currently being burned.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $cat = $burner->get_cat

Returns the category to which the story returned by get_story() is currently being burned.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $page = $burner->get_page

Returns the index number of the page that's currently being burned. The index is 0-based. The first page is "0", the second page is "1" and so on.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $output_filename = $burner->get_output_filename

Returns the base name used to create the file names of all files created by the current burn. This will have the same value as $burner->get_oc->get_filename.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $output_ext = $burner->get_output_ext

Returns the filename extension used to create the file names of all files created by the current burn. This will have the same value as $burner->get_oc->get_file_ext.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $output_path = $burner->get_base_path

Returns the local file system path to the directory that will be used as the base path for all files written for documents within a given output channel.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $output_path = $burner->get_output_path

Returns the local file system path to the directory into which all files created by the current burn will be written.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $base_uri = $burner->get_base_uri

Returns the base URI to the directory into which all files created by the current burn will be written.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$b = $burner->set_page_extensions(@page_extensions)

Sets page extensions to be used during burning. Will revert to page numbering once the extensions are all used. Each of the page extensions passed must be unique or an exception will be thrown.

Throws: NONE.

Side Effects: NONE.

Notes:

Example:

$burner->set_page_extensions(qw(intro main conc));
$burner->display_pages('page');

for a 3 page story with a slug of story and a filetype of html will produce burnt pages with filenames storyintro.html, storymain.html, and storyconc.html.

my @page_extensions = $burner->get_page_extensions();

Returns the page extensions to be used during burning.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$b = $burner->set_page_numb_start($start);

Sets the start to be used when numbering pages after array passed to set_page_extensions has been exhausted.

Throws: NONE.

Side Effects: NONE.

Notes:

Normally after all page extension strings have been used, pages are numbered using the page number, where the first page after the explicitly named pages is page 1.

Setting page extensions to qw(en de) and burning three pages will give:

storyen.html storyde.html story1.html

If you want numbering to correspond to the actual story page number, then you would pass the number of page extensions plus 1.

my $page_numb_start = $burner->get_page_numb_start;

Returns the page extension start.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$success = $burner->deploy($fa);

Deploys a template to the file system. If the burner object was provided with a user_id, the template is deployed into the user's sandbox.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$success = $burner->undeploy($fa);

Deletes a template from the file system. If the burner object was provided with a user_id, the template is undeployed from the user's sandbox.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$url = $burner->preview($ba, $key, $user_id, $oc_id);

Sends story or media to preview server and returns URL. Params:

$ba

A business asset object to preview.

$key

The string "story" or "media".

$user_id

The ID of the user publishing the asset.

$oc_id

Output channel ID (optional).

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$url = $b->preview_another($ba, $oc_id);

Burns a story or media document, distributes it to the preview server and returns the URL. It is designed to be the complement of publish_another(), to be used in templates during previews to burn and distribute related documents so that they'll be readily available on the preview server within the context of previewing another document. Like publish_another(), it will not bother to preview the document if it's the same story as the currently burning story. The supported arguments are:

$ba

A business asset object to burn and send to the preview server.

$oc_id

The ID of the output channel to use to burn a story. Defaults to the primary output channel of the story.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$published = $burner->publish($ba, $key, $user_id, $publish_date);

Publishes an asset, then remove from workflow. Returns 1 if publish was successful, else 0. Parameters are:

$ba

A business asset object to publish.

$key

The string "story" or "media".

$user_id

The ID of the user publishing the asset.

$publish_date

The date to set to schedule publishing job. If not defined it will default set up the asset to be published immediately.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$burner->publish_another($ba);
$burner->publish_another($ba);
$burner->publish_another($ba, $publish_time);
$burner->publish_another($ba, $publish_time, $anytime);

Designed to be called from within a template, this method publishes a document other than the one currently being published. This is useful when a template for one document type needs to trigger the publish of another document. Look up that document via the Bricolage API and then pass it to this method to have it published at the same time as the story currently being published.

If the mode isn't PUBLISH_MODE or if the document passed in is the same story as the currently burning story, the publish will not actually be executed. Pass in a DateTime string to specify a different date and time to publish the document. If that date is in the future, a publish job will be schedule at that time. Pass in a true value as the third argument to trigger the publish in any mode, including PREVIEW_MODE (not recommended).

Note that any values stored in the notes attribute of the current burner will be copied to the new burner that burns the new document, unless the $publish_time agrument schedules the document to be published at a future time.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

@resources = $burner->burn_one($ba, $oc, $cat);

Burn an asset in a given output channel and category, this is usually called by the preview or publish method. Returns a list of resources burned.

Parameters are:

$ba

A business asset object to burn.

$oc

The output channel to which to burn the asset.

$cat

A category in which to burn the asset.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $bool = $burner->chk_syntax($ba, \$err)

Compiles the template found in $ba. If the compile succeeds with no errors, chk_syntax() returns true. Otherwise, it returns false, and the error will be in the $err varible passed by reference.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $page_file = $burner->page_file($number)
% # Mason syntax.
% my $page_file = $burner->page_file($number);
<a href="<% $page_file %>">Page Number <% $number %></a>

Returns the file name for a page in a story as the story is being burned. The page number must be greater than 0.

Throws:

Side Effects: NONE.

Notes: This method does not check to see if the page number passed in is actually a page in the story. Caveat templator.

my $page_uri = $burner->page_uri($number)
% # Mason syntax.
% my $page_uri = $burner->page_uri($number);
<a href="<% $page_uri %>">Page Number <% $number %></a>

Returns the URI for a page in a story as the story is being burned. The page number must be greater than 0.

Throws:

Side Effects: NONE.

Notes: This method does not check to see if the page number passed in is actually a page in the story. Caveat templator.

my $page_filepath = $burner->page_filepath($number)

Returns the complete local file system file name for a page in a story as the story is being burned. The page number must be greater than 0.

Throws:

Side Effects: NONE.

Notes: This method does not check to see if the page number passed in is actually a page in the story. Caveat templator.

my $prev_page_file = $burner->prev_page_file
% if (my $prev = $burner->prev_page_file) {
    <a href="<% $prev %>">Previous Page</a>
% }

Returns the file name for the previous file in a story as the story is being burned. If there is no previous file, prev_page_file() returns undef.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $prev_page_uri = $burner->prev_page_uri
% if (my $prev = $burner->prev_page_uri) {
    <a href="<% $prev %>">Previous Page</a>
% }

Returns the URI for the previous file in a story as the story is being burned. If there is no previous URI, prev_page_uri() returns undef.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $next_page_file = $burner->next_page_file
% if (my $next = $burner->next_page_file) {
    <a href="<% $next %>">Next Page</a>
% }

Returns the file name for the next file in a story as the story is being burned. If there is no next file, next_page_file() returns undef.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $next_page_uri = $burner->next_page_uri
% if (my $next = $burner->next_page_uri) {
    <a href="<% $next %>">Next Page</a>
% }

Returns the URI for the next file in a story as the story is being burned. If there is no next URI, next_page_uri() returns undef.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $uri = $burner->best_uri($story)
% if (my $rel_story = $element->get_related_story) {
    <a href="<% $burner->best_uri($rel_story)->as_string %>">
      <% $rel_story->get_title %>
    </a>
% }

Returns a URI object representing Bricolage's best guess as to the appropriate URI to use to link to the story or media object passed as an argument. See the URI docs for information on its interface. The semantics that best_uri() uses to create the URI are as follows:

First, it checks to see if the asset's Site ID is the same as the the Site ID for the current output channel. If it is, then the URI is returned without the protocol or server name, but formatted for either the current output channel or for the document's primary output channel.

If the document isn't in the current output channel's site, best_uri() looks for an alias to the document in the current output channel's site. If there is one the alias is used to create the URI, and the URI is returned without the protocol or server name, but formatted for either the current output channel or for the alias' primary output channel.

And finally, if the document is in another site and there is no alias in the current site, best_uri() will return a full URI with the prtocol and the document's site's domain name, formatted according to the settings of the document's primary output channel.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$burner->notes
my $notes = $burner->notes;
while (my ($k, $v) = each %$notes) {
    print "$k => $v\n";
}

my $last = 10;
$burner->notes( last_story => $last );
$last = $burner->notes('last_story');

The notes() method provides a place to store burn data data, giving template developers a way to share data among multiple burns over the course of publishing a single story in a single category to a single output channel. Any data stored here persists for the lifetime of the burner object, as well as to any burners generated by calls to publish_another() or preview_another(). Use clear_notes() to manually clear the notes.

Conceptually, notes() contains a hash of key-value pairs. notes($key, $value) stores a new entry in this hash. notes($key) returns a previously stored value. notes() without any arguments returns a reference to the entire hash of key-value pairs.

notes() is similar to the mod_perl method $r->pnotes(). The main differences are that this notes() can be used in a non-mod_perl environment (such as when a story is published by bric_queued), and that its lifetime is tied to the lifetime of the burner object.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$burner->clear_notes
$cb_request->clear_notes;

Use this method to clear out the notes hash.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$burner->throw_error(@message);
my $media = $element->get_related_media or $burner->throw_error(
    'Hey, you forgot to associate a media document! ',
    'What were you thinking?',
);

Throws a Bric::Util::Fault::Exception::Burner::User exception. The arguments passed to the method will be joined into a single erroor message that will be displayed in the UI so that your user can see any mistakes you caught and fix them.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Protected Class Methods

__PACKAGE__->_register_burner(@args)
__PACKAGE__->_register_burner( Bric::Biz::AssetType::BURNER_TEMPLATE,
                               category_fn => 'category',
                               exts        =>
                                 { 'pl'   => 'HTML::Template Script (.pl)',
                                   'tmpl' => 'HTML::Template Template (.tmpl)'
                                 }
                             );

Protected method only called by Burner subclasses when they're loaded. This method registers the subclasses, along with their Bric::Biz::AssetType constants, file names, and file extenstions. Note that the category_fn and must be unique among all burners, as must the file extensions passed via the exts directive.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Private Instance Methods

$burner->_get_subclass($ba)

Returns the subclass of Bric::Util::Burner appropriate for handling the $ba template object.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

NOTES

NONE.

AUTHOR

Garth Webb <garth@perijove.com>

Sam Tregar <stregar@about-inc.com>

Matt Vella <mvella@about-inc.com>

David Wheeler <david@justatheory.com>

SEE ALSO

Bric, Bric::Util::Burner::Mason, Bric::Util::Burner::Template.