File: HTML.pm

package info (click to toggle)
libcatmandu-html-perl 0.02%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 305; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 1,540 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package Catmandu::Exporter::HTML;

our $VERSION = '0.02';

use Catmandu::Sane;
use Moo;
use namespace::clean;

with 'Catmandu::Exporter';

sub add {
    my ($self,$data) = @_;

    my $token = $data->{html} // [];

    for (@$token) {
        my $type = $_->[0];

        if ($type eq 'S') {
            $self->fh->print($_->[4]);
        }
        elsif ($type eq 'E') {
            $self->fh->print($_->[2]);
        }
        elsif ($type eq 'T') {
            $self->fh->print($_->[1]);
        }
        elsif ($type eq 'C') {
            $self->fh->print($_->[1]);
        }
        elsif ($type eq 'D') {
            $self->fh->print($_->[1]);
        }
        elsif ($type eq 'PI') {
            $self->fh->print($_->[2]);
        }
    }
}

sub commit {
    my $self = $_[0];
    $self->fh->close;
}

1;

__END__

=pod

=head1 NAME

Catmandu::Exporter::HTML - a HTML exporter

=head1 SYNOPSIS

    # From the commandline
    $ catmandu convert HTML --fix myfixes to HTML < ex/test.html

    # From Perl

    use Catmandu;

    # Print to STDOUT
    my $exporter = Catmandu->exporter('HTML');

    $exporter->add_many($arrayref);
    $exporter->add_many($iterator);
    $exporter->add_many(sub { });

    $exporter->add($hashref);

    printf "exported %d objects\n" , $exporter->count;

    # Get an array ref of all records exported
    my $data = $exporter->as_arrayref;

=head1 DESCRIPTION

This is a L<Catmandu::Exporter> for converting Perl into HTML.

=head1 SEE ALSO

L<Catmandu::Importer::LIDO>, L<HTML::TokeParser>

=cut