package Pod::POM::View::SPIP; require 5.004; use strict; use Pod::POM::View; use base qw( Pod::POM::View ); use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $INDENTLEVEL ); use Text::Wrap; $VERSION = 0.03; $DEBUG = 0 unless defined $DEBUG; $INDENTLEVEL = 0; =head1 NAME Pod::POM::View::SPIP - POD Object Model View for SPIP =head1 SYNOPSIS use Pod::POM::View::SPIP; my $parser = Pod::POM->new(\%options); # parse from a text string my $pom = $parser->parse_text($text) || die $parser->error(); # parse from a file specified by name or filehandle my $pom = $parser->parse_text($file) || die $parser->error(); # parse from text or file my $pom = $parser->parse($text_or_file) || die $parser->error(); print Pod::POM::View::SPIP->print($pom); =head1 DESCRIPTION SPIP is a popular CMS in France, and as POD is also a popular text format to write articles, we needed a way to translate POD text into SPIP markup. This view for L implements it. =head1 METHODS =head2 new Class constructor. Used by L. =cut sub new { my $class = shift; my $self = $class->SUPER::new(@_) || return; # initalise stack for maintaining info for nested lists $self->{ INDENTLEVEL } = 0; return $self; } =head1 VIEW DETAILS =over =item * view Implement L C method =cut sub view { my ($self, $type, $item) = @_; if ($type =~ s/^seq_//) { return $item; } elsif (UNIVERSAL::isa($item, 'HASH')) { if (defined $item->{content}) { return $item->{content}->present($self); } elsif (defined $item->{text}) { my $text = $item->{text}; return ref $text ? $text->present($self) : $text; } else { return ''; } } elsif (! ref $item) { return $item; } else { return ''; } } =pod =item * view_head1 C<=head1> POD sections are translated to the following SPIP markup: =head1 Title becomes: {{{Title}}} which is the SPIP classic title markup. =cut sub view_head1 { my ($self, $head1) = @_; my $output = "\n{{{" . $head1->title->present($self)."}}}\n\n" . $head1->content->present($self); return $output; } =pod =item * view_head2 C<=head2> POD sections are translated to the following SPIP markup: =head2 Title becomes: - {{Title}} which is first level item list with bold text. Remember that first level lists in SPIP are bulleted with an image (I). =cut sub view_head2 { my ($self, $head2) = @_; my $output = "\n- {{" . $head2->title->present($self)."}}\n\n" . $head2->content->present($self); return $output; } =pod =item * view_head3 C<=head3> POD sections are translated to the following SPIP markup: =head3 Title becomes: - {Title} which is first level item list with italic text. =cut sub view_head3 { my ($self, $head3) = @_; my $output = "\n- {" . $head3->title->present($self)."}\n\n" . $head3->content->present($self); return $output; } =item * view_head4 C<=head4> POD sections are translated to the following SPIP markup: =head4 Title becomes: -* {Title} which is second level item list with italic text. In SPIP, second level itemized lists are then translated to EULE HTML tags. =cut sub view_head4 { my ($self, $head4) = @_; my $output = "\n-* {" . $head4->title->present($self)."}\n\n" . $head4->content->present($self); return $output; } =item * view_over C only counts indent levels. =cut sub view_over { my ($self, $over) = @_; my $indentlevel = ref $self ? \$self->{ INDENTLEVEL } : \$INDENTLEVEL; $$indentlevel++; my $content = $over->content->present($self); $$indentlevel--; return $content; } =item * view_item C<=item> POD sections (enclosed between C<=over> & C<=back>) are translated to the following SPIP markup: =over =item First level item (no explicit bullet) =item * First level item (with bullet) =over =item * Second level item (with bullet) =item 1 Second level numbered item =item 1 Second level numbered item =back =item 1. First level numbered item =item 1. First level numbered item =back become respectively: _First level item (no bullet) -* First level item (with bullet) -** Title -## Title -## Title -# Title -# Title When multiple nested lists advent, the imbrication levels are respected. Be careful to specify bullets for sub-level lists, as SPIP only allows them on the first level (C<_> prefix). =cut sub view_item { my ($self, $item) = @_; my $indentlevel = ref $self ? \$self->{INDENTLEVEL} : \$INDENTLEVEL; my $title = $item->title->present($self); my $content = $item->content->present($self); $content =~ s/(?:\r?\n)+$//m; # Taken from Pod::POM::View::HTML::view_over if ($title =~ /^\s*\*\s*/ || ($title =~ /^\s[^*]/ && $indentlevel > 1)) { # '=item *' =>