App-MakeEPUB

 view release on metacpan or  search on metacpan

examples/rfc/bin/rfc2xhtml.pl  view on Meta::CPAN

};

sub new {
    my ($self,$args) = @_;
    my $type = ref($self) || $self;

    $self = bless {}, $type;
    $self->_init($args);
    return $self;
} # new();

sub event {
    my ($self,$event,@args) = @_;
    my ($action,$next);
    my $sn      = $self->{state};
    my $state   = $state_table->{$sn};
    my $default = $state_table->{default};

    if ($state->{$event}) {
        $next   = $state->{$event}->[0] || $sn;
        $action = $state->{$event}->[1];
    }
    elsif ($default->{$event}) {
        $next   = $default->{$event}->[0] || $sn;
        $action = $default->{$event}->[1] || $sn;
    }
    elsif ($state->{default}) {
        $next   = $state->{default}->[0] || $sn;
        $action = $state->{default}->[1];
    }
    elsif ($default->{default}) {
        $next   = $default->{default}->[0] || $sn;
        $action = $default->{default}->[1];
    }
    else {
        my $line = $args[0] || '';
        die "FSM: can't handle event($event) in state($sn): $line";
    }
    $self->{nextstate} = $next;
    $action->($self,$event,@args);
    $next = $self->{nextstate};
    if ($state_table->{$next}) {
        $self->{state} = $next;
    }
    else {
        my $line = $args[0] || '';
        die "FSM: unknown next state($next)\n"
          . "     after event($event) in state($sn): $line";
    }
} # event()

sub start {
    my ($self,$args) = @_;

    if ($args) {
        $self->_init($args);
    }
    my $xmlns   = $self->{xmlns};
    my $title   = $self->{title};
    my $head = <<"EOHEAD";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="$xmlns">
<head ><title >$title</title>
<link rel="stylesheet" href="rfc.css" type="text/css" />
</head>
<body>
EOHEAD
    print $head;
    $self->{state} = 'start';
} # start()

sub stop {
    my ($self) = @_;
    my $foot    = <<EOFOOT;
</body>
</html>
EOFOOT
    print $foot;
    $self->{state} = 'stop';
} # stop();

sub _abort {
    my ($self,$event,$line,$args) = @_;
    my @args = sort map { "$_($args->{$_})" } keys %$args;
    my $state = $self->{state};
    my $text = $args->{text} ? $args->{text} : $line;
    die join("\n  ","abort in state($state), event($event)"
        , "line($line)",@args)
} # _abort_event()

sub _begin_h2 {
    my ($self,$event,$line,$args) = @_;
    my $id = $args->{id} || '';

    $self->_catch_unfinished_paragraph();
    $self->{lasttext} = [];
    print qq(<h2><a id="section-$id">$line</a></h2>\n);
} # _begin_h2()

sub _begin_h3 {
    my ($self,$event,$line,$args) = @_;
    my $id = $args->{id} || '';

    $self->_catch_unfinished_paragraph();
    $self->{lasttext} = [];
    print qq(<h3><a id="section-$id">$line</a></h3>\n);
} # _begin_h3()

sub _begin_h4 {
    my ($self,$event,$line,$args) = @_;
    my $id = $args->{id} || '';

    $self->_catch_unfinished_paragraph();
    $self->{lasttext} = [];
    print qq(<h4><a id="section-$id">$line</a></h4>\n);
} # _begin_h4()

sub _begin_h5 {
    my ($self,$event,$line,$args) = @_;
    my $id = $args->{id} || '';



( run in 1.482 second using v1.01-cache-2.11-cpan-e1769b4cff6 )