Changeset 1521

Show
Ignore:
Timestamp:
08/20/06 20:29:02
Author:
miyagawa
Message:

Added Plagger::Content module, which is a data representing text data which might be plaintext or html snippet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/hackathon-summary/plagger/lib/Plagger/Entry.pm

    r1173 r1521  
    33 
    44use base qw( Plagger::Thing ); 
    5 __PACKAGE__->mk_accessors(qw( title author tags link feed_link id summary body rate icon meta source )); 
     5__PACKAGE__->mk_accessors(qw( tags link feed_link id rate icon meta source )); 
     6__PACKAGE__->mk_content_accessors(qw( title author summary body )); 
    67__PACKAGE__->mk_date_accessors(qw( date )); 
    78 
     
    6364sub title_text { 
    6465    my $self = shift; 
    65     Plagger::Util::strip_html($self->title)
     66    $self->title->plaintext
    6667} 
    6768 
    6869sub body_text { 
    6970    my $self = shift; 
    70     Plagger::Util::strip_html($self->body || '')
     71    $self->body->plaintext
    7172} 
    7273 
  • branches/hackathon-summary/plagger/lib/Plagger/Feed.pm

    r1386 r1521  
    33 
    44use base qw( Plagger::Thing ); 
    5 __PACKAGE__->mk_accessors(qw( link url image description language author tags meta type source_xml aggregator )); 
     5__PACKAGE__->mk_accessors(qw( link url image language tags meta type source_xml aggregator )); 
     6__PACKAGE__->mk_content_accessors(qw( description author title )); 
    67__PACKAGE__->mk_date_accessors(qw( updated )); 
    78 
     
    4243} 
    4344 
    44 sub title { 
    45     my $self = shift; 
    46     if (@_) { 
    47         my $title = shift; 
    48         utf8::decode($title) unless utf8::is_utf8($title); 
    49         $self->{title} = $title; 
    50     } 
    51     $self->{title}; 
    52 } 
    53  
    5445sub id { 
    5546    my $self = shift; 
     
    6859sub title_text { 
    6960    my $self = shift; 
    70     Plagger::Util::strip_html($self->title)
     61    $self->title->plaintext
    7162} 
    7263 
  • branches/hackathon-summary/plagger/lib/Plagger/Thing.pm

    r1024 r1521  
    22use strict; 
    33use base qw( Class::Accessor::Fast ); 
     4 
     5use Plagger::Content; 
    46 
    57sub has_tag { 
     
    4345} 
    4446 
     47sub mk_content_accessors { 
     48    my $class = shift; 
     49    for my $key (@_) { 
     50        no strict 'refs'; 
     51        *{"$class\::$key"} = sub { 
     52            my $obj = shift; 
     53            if (@_) { 
     54                my $content = $_[0]; 
     55                unless (ref($content)) { 
     56                    $content = Plagger::Content->new_from_text($content); 
     57                } 
     58                $obj->{$key} = $content; 
     59            } else { 
     60                return $obj->{$key}; 
     61            } 
     62        }; 
     63    } 
     64} 
     65 
    45661;