| Bryar documentation | Contained in the Bryar distribution. |
Bryar::Document - Represents a blog post
$self->new(...);
$self->content(); # Get content
$self->title(); # Get title
$self->epoch(); # Get epoch
$self->timepiece(); # Get the date as a Time::Piece object
$self->category(); # Get category
$self->author(); # Get author
$self->keywords(...); # Return keywords relating to this document
$self->id # Unique identifier
$self->comments(); # Get comments
This encapsulates a blog post, as returned from a search on a data source.
$self->new(%params)
Creates a new Bryar::Document instance.
$self->content(); # Get content
Gets the value of the document's content
$self->title(); # Get title
Gets the value of the document's title
$self->epoch(); # Get epoch
Gets the value of the document's epoch
Returns the date of the document as a Time::Piece object.
Returns the date of the document as a DateTime object
$self->category(); # Get category
Gets the value of the document's category
$self->keywords
Returns the keywords for this blog entry, using Lingua::EN::Keywords
if it's installed. May be computationally expensive!
$self->id(); # Get id
Returns a unique identifier for the document.
$self->url;
Returns the post url relative to $bryar->config->baseurl.
my $excerpt = $self->excerpt(20); # get a 20 word excerpt my $excerpt = $self->excerpt( ); # get excerpt as long as the excerpt_words config variable
This module is free software, and may be distributed under the same terms as Perl itself.
Copyright (C) 2003, Simon Cozens simon@kasei.com
| Bryar documentation | Contained in the Bryar distribution. |
package Bryar::Document; use Time::Piece; use 5.006; use strict; use warnings; use Carp; our $VERSION = '1.0';
sub new { my $class = shift; my %args = @_; my $self = bless { epoch => $args{epoch} , content => $args{content} , author => $args{author} , category => $args{category} , title => $args{title} , id => $args{id}, comments => ($args{comments} || []) }, $class; return $self; }
sub content { my $self = shift; return $self->{content}; }
sub title { my $self = shift; return $self->{title}; }
sub epoch { my $self = shift; return $self->{epoch}; }
sub timepiece { my $self = shift; return Time::Piece->new($self->{epoch}); }
sub datetime { my $self = shift; return DateTime->from_epoch( epoch => $self->{epoch}, time_zone => "local" ); }
sub category { my $self = shift; return $self->{category}; }
sub author { my $self = shift; return $self->{author}; }
sub keywords { my $self = shift; eval { require Lingua::EN::Keywords; }; return "" if $@; return Lingua::EN::Keywords::keywords($self->content); # Goodbye, CPU time! }
sub id { my $self = shift; return $self->{id}; }
sub url { my $self = shift; my $id = $self->{id}; $id =~ s#^.*/##; my $url = ''; $url = '/' . $self->{category} if $self->{category} ne 'main'; return $url . '/id_' . $id; }
sub comments { my $self = shift; return @{$self->{comments}}; }
sub excerpt { my $self = shift; my $num_words = shift || 40; my $content = $self->{content}; # NOTE: I lifted this from MT, but in reality, i will be making it more flexible and neater. # Now if only this document had some sense of the Bryar environment so it could pull the # default $num_words from the config. # $text = remove_html($text); my @words = split /\s+/, $content; my $max_words = @words > $num_words ? $num_words : @words; return join ' ', @words[0..$max_words-1]; }
1;
Returns a list of Bryar::Comment objects attached to this document.