Text::Hatenaを拡張してみた

1. テストコード

use strict;
use warnings;
use utf8;
use Test::Base;
use CMS::Lite::Extend::Text::Hatena;

filters {
    text => ['my_parse', 'omit_indent', 'chomp'],
    html => ['omit_indent', 'chomp'],
};

sub my_parse { CMS::Lite::Extend::Text::Hatena->parse(shift, 'body') }

sub omit_indent {
    my $text = shift;
    $text =~ s/^[\t\s]+//gmo;
}

run_is;

__END__
=== description
--- text
description: test
--- html
<div class="section">
<p id="description">test</p>
</div>

2. 拡張したモジュール

package CMS::Lite::Extend::Text::Hatena;
use strict;
use warnings;
use utf8;
use base qw(Text::Hatena);

__PACKAGE__->syntax(q|
    block       : description
    description : "\ndescription: " inline(s)

|);

sub description {
    my $class = shift;
    my $items = shift->{items};
    my $description = $class->expand($items->[1]);
    return if $description =~ /^desc/;
    return qq{<p id="description">$description</p>\n};
}
=cut

=encoding utf-8

=for stopwords

=head1 NAME

CMS::Lite::Extend::Text::Hatena - I need to extend Text::Hatena.

=head1 METHODS

=head2 description

=cut

1;

3. 実行結果

:!prove -vl t/101-extend_text_hatena.t
t/101-extend_text_hatena.t ..
ok 1 - h3+description
1..1
ok
All tests successful.

See Also

  • Text-Hatena-0.20/t/02_module_extend.t
  • Text-Hatena-0.20/t/lib/MyParser.pm