package WWW::AdventCalendar::Article; { $WWW::AdventCalendar::Article::VERSION = '1.108'; } use Moose; # ABSTRACT: one article in an advent calendar use autodie; use Digest::MD5 qw(md5_hex); use Email::Address; use Pod::Elemental; use Pod::Elemental::Transformer::Pod5; use Pod::Elemental::Transformer::SynMux; use Pod::Elemental::Transformer::Codebox; use Pod::Elemental::Transformer::PPIHTML; use Pod::Elemental::Transformer::VimHTML; use Pod::Elemental::Transformer::List; use Pod::Simple::XHTML 3.13; use namespace::autoclean; has date => (is => 'ro', isa => 'DateTime', required => 1); has [ qw(author title topic body) ] => ( is => 'ro', isa => 'Str', required => 1, ); sub author_email { my ($self) = @_; my ($addr) = Email::Address->parse($self->author); return($addr ? $addr->address : md5_hex($self->author) . q{@advcal.example.com}); } sub author_name { my ($self) = @_; my ($addr) = Email::Address->parse($self->author); return($addr ? $addr->name : $self->author); } has calendar => ( is => 'ro', isa => 'WWW::AdventCalendar', required => 1, weak_ref => 1, ); has body_html => ( is => 'ro', lazy => 1, init_arg => undef, builder => '_build_body_html', ); sub _build_body_html { my ($self) = @_; my $body = $self->body; $body = "\n=encoding utf-8\n\n$body" unless $body =~ /^=encoding/s; my $document = Pod::Elemental->read_string($body); Pod::Elemental::Transformer::Pod5->new->transform_node($document); Pod::Elemental::Transformer::List->new->transform_node($document); my $mux = Pod::Elemental::Transformer::SynMux->new({ transformers => [ Pod::Elemental::Transformer::Codebox->new, Pod::Elemental::Transformer::PPIHTML->new, Pod::Elemental::Transformer::VimHTML->new, ], }); $mux->transform_node($document); $body = $document->as_pod_string; my $parser = Pod::Simple::XHTML->new; $parser->perldoc_url_prefix('https://metacpan.org/module/'); $parser->output_string(\my $html); $parser->html_h_level(2); $parser->html_header(''); $parser->html_footer(''); $parser->parse_string_document( Encode::encode('utf-8', $body) ); $html = "
)\s*
(