Apache-Wyrd

 view release on metacpan or  search on metacpan

Wyrd/Site/Page.pm  view on Meta::CPAN

=item section

The section of the site, i.e. first branch of the tree this page belongs to in
the navigational hierarcy.  See C<Apache::Wyrd::Site> and C<Apache::Wyrd::Site::NavPull>.

=item allow/deny

Authorization tags.  The default C<Apache::Wyrd::Services::Auth>,
C<Apache::Wyrd::User>, and related classes operate by checking levels of
authorization.  Users are assigned levels and what they are allowed to
access depend on what levels are required.  If "allow" is not set, the page
is considered public.  If it is, only authenticated users with the security
level indicated by the tags are allowed access.  If "deny" is set, those
users who would normally have access by virtue of the allow value are denied
if they match one of the deny tags.

=item tags

Tokens used to classify the Page by subject matter.  These are used by
C<Apache::Wyrd::Site::TagPull> to create lists of documents by subject
metadata.

=item original

The location of the document if this page is proxying for another document. 
For example, if the document is located site-root-relative pdfs/thispdf.pdf,
the attribute would be "/pdfs/thispdf.pdf".  You would then want to set the
doctype to "PDF" so that your pull can indicate that the doctype is PDF, not
HTML.

=item doctype

The type of document (defaults to "HTML").

=item expires

A date attribute.  Not currently used by the default Wyrds in this
hierarchy, but often proves useful in determining when something should no
longer be considered new.

=item longdescription

In some pulls, a longer description can be useful.  This allows that
description to be used, and defaults to the value of "description" when it
is not provided.

=item shorttitle

Especially in NavPulls, the actual title of a page may be too cumbersome. 
This allows for a shorter alternate.

=item etc., etc.,

Other indexible attributes may be added in subclasses.  Note that the
attributes should be given as parameters to the index object (so it knows to
look for and store them).  If the index object is SQL-type, the attributes
should be added to the underlying main table (normaly _wyrd_index), an
index_xxxxx method needs to be made to properly supply that value to the
index, and either the more_info method be defined to add all the data from
these attributes to the data fingerprint, or the index_digest call
SUPER::index_digest with the additional data as an argument (single scalar).
 See C<Apache::Wyrd::Services::Index> and
C<Apache::Wyrd::Interfaces::Indexible>.

=back

=head2 FLAGS

=over

=item nofail

If a document is supplied to the "original" attribute and the document does
not exist, Page will normally terminate with a fatal error.  This forces
Page to ignore the error.  It's normal use is to allow external
sites/documents to be referenced by a Page Wyrd (i.e. by using the full
URL).

=back

=head2 PERL METHODS

I<(format: (returns) name (arguments after self))>

=over

=item (void) C<_init_state> (void)

Internal method for initializing the widget substructure.

=cut

sub _init_state {
	my ($self) = @_;
	#initialize the counter which will record the number of widgets
	$self->{'_state_counter'} = 0;

	#if the state information has arrive via CGI, set the _override marker to indicate that
	#the new state will have precedence over the default state, and decode that information
	#into the _state holding key
	my $string = $self->{'_override'} = $self->_state_string;
	$self->{'_state'} = $self->_decode_state($string) if ($string);
}

=item (scalar) C<_state_digit> (void)

=item (scalar) C<_state_symbol> (void)

Internal methods for mapping widget states to values

=cut

#return the number associated with the character
sub _state_digit {
	return $decode{$_[1]};
}

#return the nth character
sub _state_symbol {
	return $encode[$_[1]];
}

Wyrd/Site/Page.pm  view on Meta::CPAN

=item (void) C<_page_edit> (void)

A hook method for pages which interact with some sort of content management editing facility.

=cut

sub _page_edit {
	my ($self) = @_;
	return;
}

=item (void) C<_process_template> (void)

A hook method for how to assemble the body section of the page from the
template.  Defaults to replacing the string _INSERT_TEXT_HERE_ with the
enclosed text.

=cut

sub _process_template {
	my ($self, $template) = @_;
	$template =~ s/_INSERT_TEXT_HERE_/$$self{_data}/;
	$self->{_data} = $template;
}

=item (array) C<_attribute_list> (void)

=item (array) C<_map_list> (void)

List of those attributes supported by this Page object that are tracked in
the the attributes of the Index object that supports it.  The default is to
use the Index object's attribute and map lists, respectively.  See
C<qw(Apache::Wyrd::Site::Index)> and C<qw(Apache::Wyrd::Services::Index)>.

=cut

#index-dependent attribute list
sub _attribute_list {
	my ($self) = @_;
	return ($self->index->attribute_list);
}

sub _map_list {
	my ($self) = @_;
	return $self->index->map_list;
}

#overloads Indexable

=item (scalar) C<index_digest> (void)

As in C<Apache::Wyrd::Interfaces::Indexable>, provides the raw data to be
considered in generating the "fingerprint" that is used to determine if this
page has been changed, and consequently requires re-indexing.

=cut

sub index_digest {
	my ($self, $extra) = @_;
	$extra ||= '';
	return $self->SUPER::index_digest(
		  $self->index_parent
		. $self->index_published
		. $self->index_section
		. $self->index_allow
		. $self->index_deny
		. $self->index_tags

		. $self->index_doctype
		. $self->index_expires
		. $self->index_longdescription
		. $self->index_shorttitle

		. $self->more_info
		. $extra
	);
}

=item (scalar) C<more_info> (void)

A hook method for adding information to the fingerprint for C<index_digest>.

=cut

sub more_info {
	return;
}

=item (scalar) C<index_*> (void)

Methods used to provide this fingerprint data, per
C<Apache::Wyrd::Interfaces::Indexable>.

One of the default methods provided in this class is C<index_children>,
which also provides for the arbitrary order of children of a parent.  See
C<Apache::Wyrd::Site::NavPull> for an explanation of this feature.

Also by default, the C<index_name> method will return the "original"
attribute if set, to allow the page to proxy for another document.

=cut

#handled by Indexable: name reverse timestamp digest data count title keywords description

#Abstract Page attributes: parent file published section allow deny tags children

sub index_name {
	my ($self) = @_;
	return $self->{'original'} || $self->SUPER::index_name();
}

sub index_parent {
	my ($self) = @_;
	return $self->{'parent'};
}

sub index_file {
	my ($self) = @_;
	return $self->dbl->self_path;
}

sub index_published {
	my ($self) = @_;
	return $self->{'published'};
}

sub index_section {
	my ($self) = @_;
	return $self->{'section'};
}

sub index_allow {
	my ($self) = @_;
	return $self->{'allow'};
}

sub index_deny {
	my ($self) = @_;
	return $self->{'deny'};
}

sub index_tags {
	my ($self) = @_;
	return $self->{'tags'};
}

sub index_children {
	my ($self) = @_;
	return $self->{'parent'};
}

sub handle_children {
	my ($self, $id, $parent) = @_;
	my @parents = token_parse($parent);
	my %score = ();
	foreach $parent (@parents) {
		($parent, my $score) = split(':', $parent);
		$score{$parent} = $score;
	}
	$self->index->index_map('children', $id, \%score);
}

#The list goes on and on

sub index_doctype {
	my ($self) = @_;
	return ($self->{'doctype'} || 'HTML');
}

Wyrd/Site/Page.pm  view on Meta::CPAN

=back

=head1 BUGS/CAVEATS

Reserves the _format_output and _generate_output methods.

=cut

sub _setup {
	my ($self) = @_;
	$self->_init_state;
	$self->_check_auth;
	$self->_init_index;
	$self->_page_edit;
	unless ($self->_flags->nofail) {
		my $name = $self->index_name;
		if ($name eq $self->{'original'}) {
			if ($name =~ m/^\//) {
				unless (-f $self->dbl->req->document_root . $name) {
					$self->_raise_exception("Original file doesn't exist ($name).  Use the nofail flag to override this error.");
				}
			}
		}
	}
}

sub _format_output {
	my ($self) = @_;
	my $response = $self->index->update_entry($self);
	$self->_info($response);
	$self->_set_state;
	my $head = join ('/', $self->dbl->req->document_root, 'lib/head.html');
	my $file = join ('/', $self->dbl->req->document_root, 'lib/body.html');
	my $template = $self->get_cached($head);
	my $title = $self->{'title'};
	my $keywords = $self->{'keywords'};
	my $description = $self->{'description'};
	my $meta = $self->{'meta'};
	$template =~ s/<\/head>/\n$meta\n<\/head>/ if ($meta);
	my $lib = $self->{'lib'};
	if ($lib) {
		my @inserts = token_parse($lib);
		foreach my $lib (@inserts) {
			$lib =  join ('/', $self->dbl->req->document_root, 'lib', $lib);
			$lib = $self->get_cached($lib);
			$template =~ s/<\/head>/$lib\n<\/head>/;
		}
	}
	$title =~ s/\s+/ /g;
	$keywords =~ s/\s+/ /g;
	$description =~ s/\s+/ /g;
	$template = $self->_set({title => strip_html($title), keywords => strip_html($keywords), description => strip_html($description)}, $template);
	$template .= $self->get_cached($file);
	$self->_process_template($template);
	return;
}

sub _generate_output {
	my ($self) = @_;
	$self->_dispose_index;
	return $self->SUPER::_generate_output;
}


=pod

=head1 AUTHOR

Barry King E<lt>wyrd@nospam.wyrdwright.comE<gt>

=head1 SEE ALSO

=over

=item Apache::Wyrd

General-purpose HTML-embeddable perl object

=item Apache::Wyrd::Services::Index

=item Apache::Wyrd::Services::MySQLIndex

=item Apache::Wyrd::Site::Index

=item Apache::Wyrd::Site::MySQLIndex

Various index objects for site organization.

=item Apache::Wyrd::Site

Documentation about this sub-hierarchy

=back

=head1 LICENSE

Copyright 2002-2007 Wyrdwright, Inc. and licensed under the GNU GPL.

See LICENSE under the documentation for C<Apache::Wyrd>.

=cut

1;



( run in 1.800 second using v1.01-cache-2.11-cpan-389fe586d7c )