| 1 | package Markdent::Handler::HTMLStream::Document; | ||||||||||
| 2 | |||||||||||
| 3 | 31 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 31 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 31 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 31 | our $VERSION = '0.39'; | |||||||||
| 8 | |||||||||||
| 9 | 31 | ▶ | use Markdent::Types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 31 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 31 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 31 | with 'Markdent::Role::HTMLStream'; | |||||||||
| 15 | |||||||||||
| 16 | 31 | has title => ( | |||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | isa => t('Str'), | ||||||||||
| 19 | required => 1, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 31 | has charset => ( | |||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | isa => t('Str'), | ||||||||||
| 25 | predicate => '_has_charset', | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 31 | has language => ( | |||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | isa => t('Str'), | ||||||||||
| 31 | predicate => '_has_language', | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | 31 | my $Doctype = <<'EOF'; | |||||||||
| 35 | <!DOCTYPE html> | ||||||||||
| 36 | EOF | ||||||||||
| 37 | |||||||||||
| 38 | sub start_document { | ||||||||||
| 39 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
start_document: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 40 | |||||||||||
| 41 | 1 | $self->_stream_raw($Doctype); | |||||||||
| 42 | 1 | ▶ | $self->_stream_start_tag( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 'html', { | ||||||||||
| 44 | $self->_has_language ? ( lang => $self->language ) : (), | ||||||||||
| 45 | }, | ||||||||||
| 46 | ); | ||||||||||
| 47 | 1 | $self->_stream_start_tag('head'); | |||||||||
| 48 | 1 | ▶ | $self->_stream_start_tag( 'meta', { charset => $self->charset } ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | if $self->_has_charset; | ||||||||||
| 50 | 1 | $self->_stream_start_tag('title'); | |||||||||
| 51 | 1 | $self->_stream_text( $self->title ); | |||||||||
| 52 | 1 | $self->_stream_end_tag('title'); | |||||||||
| 53 | 1 | $self->_stream_end_tag('head'); | |||||||||
| 54 | 1 | $self->_stream_start_tag('body'); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub end_document { | ||||||||||
| 58 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
end_document: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 59 | |||||||||||
| 60 | 1 | $self->_stream_end_tag('body'); | |||||||||
| 61 | 1 | $self->_stream_end_tag('html'); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 31 | __PACKAGE__->meta->make_immutable; | |||||||||
| 65 | |||||||||||
| 66 | 31 | 1; | |||||||||
| 67 | |||||||||||
| 68 | # ABSTRACT: Turns Markdent events into a complete HTML document | ||||||||||
| 69 | |||||||||||
| 70 | __END__ | ||||||||||
| 71 | |||||||||||
| 72 | =pod | ||||||||||
| 73 | |||||||||||
| 74 | =encoding UTF-8 | ||||||||||
| 75 | |||||||||||
| 76 | =head1 NAME | ||||||||||
| 77 | |||||||||||
| 78 | Markdent::Handler::HTMLStream::Document - Turns Markdent events into a complete HTML document | ||||||||||
| 79 | |||||||||||
| 80 | =head1 VERSION | ||||||||||
| 81 | |||||||||||
| 82 | version 0.39 | ||||||||||
| 83 | |||||||||||
| 84 | =head1 DESCRIPTION | ||||||||||
| 85 | |||||||||||
| 86 | This class takes an event stream and turns it into a complete HTML document. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 METHODS | ||||||||||
| 89 | |||||||||||
| 90 | This role provides the following methods: | ||||||||||
| 91 | |||||||||||
| 92 | =head2 Markdent::Handler::HTMLStream::Document->new(...) | ||||||||||
| 93 | |||||||||||
| 94 | This method creates a new handler. It accepts the following parameters: | ||||||||||
| 95 | |||||||||||
| 96 | =over 4 | ||||||||||
| 97 | |||||||||||
| 98 | =item * title => $title | ||||||||||
| 99 | |||||||||||
| 100 | The title of the document. This is required. | ||||||||||
| 101 | |||||||||||
| 102 | =item * charset => $charset | ||||||||||
| 103 | |||||||||||
| 104 | If provided, a C<< <meta charset="..."> >> tag will be added to the document's | ||||||||||
| 105 | C<< <head> >>. | ||||||||||
| 106 | |||||||||||
| 107 | =item * language => $language | ||||||||||
| 108 | |||||||||||
| 109 | If provided, a "lang" attribute will be added to the document's C<< <html> >> | ||||||||||
| 110 | tag. | ||||||||||
| 111 | |||||||||||
| 112 | =item * output => $fh | ||||||||||
| 113 | |||||||||||
| 114 | The file handle or object to which HTML output will be streamed. If you want | ||||||||||
| 115 | to capture the output in a string, you can open a filehandle to a string: | ||||||||||
| 116 | |||||||||||
| 117 | my $buffer = q{}; | ||||||||||
| 118 | open my $fh, '>', \$buffer; | ||||||||||
| 119 | |||||||||||
| 120 | If you pass a file handle (or L<IO::Handle> object), then all calls to | ||||||||||
| 121 | C<print()> will be checked, and an error will be thrown. | ||||||||||
| 122 | |||||||||||
| 123 | You can pass an object of any other class, it must implement its own | ||||||||||
| 124 | C<print()> method, and error handling is left up to this method. | ||||||||||
| 125 | |||||||||||
| 126 | =back | ||||||||||
| 127 | |||||||||||
| 128 | =head1 ROLES | ||||||||||
| 129 | |||||||||||
| 130 | This class does the L<Markdent::Role::HTMLStream>, | ||||||||||
| 131 | L<Markdent::Role::EventsAsMethods>, and L<Markdent::Role::Handler> roles. | ||||||||||
| 132 | |||||||||||
| 133 | =head1 BUGS | ||||||||||
| 134 | |||||||||||
| 135 | See L<Markdent> for bug reporting details. | ||||||||||
| 136 | |||||||||||
| 137 | Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>. | ||||||||||
| 138 | |||||||||||
| 139 | I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. | ||||||||||
| 140 | |||||||||||
| 141 | =head1 SOURCE | ||||||||||
| 142 | |||||||||||
| 143 | The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>. | ||||||||||
| 144 | |||||||||||
| 145 | =head1 AUTHOR | ||||||||||
| 146 | |||||||||||
| 147 | Dave Rolsky <autarch@urth.org> | ||||||||||
| 148 | |||||||||||
| 149 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 150 | |||||||||||
| 151 | This software is copyright (c) 2021 by Dave Rolsky. | ||||||||||
| 152 | |||||||||||
| 153 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 154 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 155 | |||||||||||
| 156 | The full text of the license can be found in the | ||||||||||
| 157 | F<LICENSE> file included with this distribution. | ||||||||||
| 158 | |||||||||||
| 159 | =cut | ||||||||||