| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Markdent/Parser.pm |
| Statements | Executed 46 statements in 6.64ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 17.4ms | 3.66s | Markdent::Parser::BEGIN@11 |
| 1 | 1 | 1 | 13.4ms | 4.00s | Markdent::Parser::BEGIN@10 |
| 1 | 1 | 1 | 65µs | 661µs | Markdent::Parser::BEGIN@14 |
| 1 | 1 | 1 | 57µs | 57µs | Markdent::Parser::BEGIN@2 |
| 1 | 1 | 1 | 55µs | 285µs | Markdent::Parser::BEGIN@16 |
| 1 | 1 | 1 | 52µs | 883µs | Markdent::Parser::BEGIN@13 |
| 1 | 1 | 1 | 49µs | 27.1ms | Markdent::Parser::BEGIN@17 |
| 1 | 1 | 1 | 48µs | 25.3ms | Markdent::Parser::BEGIN@19 |
| 1 | 1 | 1 | 47µs | 24.8ms | Markdent::Parser::BEGIN@12 |
| 1 | 1 | 1 | 47µs | 19.4ms | Markdent::Parser::BEGIN@18 |
| 1 | 1 | 1 | 39µs | 57µs | Markdent::Parser::BEGIN@6 |
| 1 | 1 | 1 | 38µs | 107µs | Markdent::Parser::BEGIN@7 |
| 1 | 1 | 1 | 26µs | 26µs | Markdent::Parser::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::BUILD |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::__ANON__[:120] |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::__ANON__[:126] |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::_build_block_parser |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::_build_span_parser |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::_class_name_for_dialect |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::_clean_text |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::_set_classes_for_dialect |
| 0 | 0 | 0 | 0s | 0s | Markdent::Parser::parse |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Markdent::Parser; | ||||
| 2 | # spent 57µs within Markdent::Parser::BEGIN@2 which was called:
# once (57µs+0s) by Markdent::Simple::Document::BEGIN@10 at line 4 | ||||
| 3 | 1 | 30µs | $Markdent::Parser::VERSION = '0.17'; | ||
| 4 | 1 | 77µs | 1 | 57µs | } # spent 57µs making 1 call to Markdent::Parser::BEGIN@2 |
| 5 | |||||
| 6 | 3 | 95µs | 2 | 74µs | # spent 57µs (39+18) within Markdent::Parser::BEGIN@6 which was called:
# once (39µs+18µs) by Markdent::Simple::Document::BEGIN@10 at line 6 # spent 57µs making 1 call to Markdent::Parser::BEGIN@6
# spent 18µs making 1 call to strict::import |
| 7 | 3 | 99µs | 2 | 175µs | # spent 107µs (38+68) within Markdent::Parser::BEGIN@7 which was called:
# once (38µs+68µs) by Markdent::Simple::Document::BEGIN@10 at line 7 # spent 107µs making 1 call to Markdent::Parser::BEGIN@7
# spent 68µs making 1 call to warnings::import |
| 8 | |||||
| 9 | 3 | 105µs | 1 | 26µs | # spent 26µs within Markdent::Parser::BEGIN@9 which was called:
# once (26µs+0s) by Markdent::Simple::Document::BEGIN@10 at line 9 # spent 26µs making 1 call to Markdent::Parser::BEGIN@9 |
| 10 | 3 | 760µs | 1 | 4.00s | # spent 4.00s (13.4ms+3.99) within Markdent::Parser::BEGIN@10 which was called:
# once (13.4ms+3.99s) by Markdent::Simple::Document::BEGIN@10 at line 10 # spent 4.00s making 1 call to Markdent::Parser::BEGIN@10 |
| 11 | 3 | 869µs | 1 | 3.66s | # spent 3.66s (17.4ms+3.64) within Markdent::Parser::BEGIN@11 which was called:
# once (17.4ms+3.64s) by Markdent::Simple::Document::BEGIN@10 at line 11 # spent 3.66s making 1 call to Markdent::Parser::BEGIN@11 |
| 12 | 3 | 165µs | 2 | 49.5ms | # spent 24.8ms (47µs+24.7) within Markdent::Parser::BEGIN@12 which was called:
# once (47µs+24.7ms) by Markdent::Simple::Document::BEGIN@10 at line 12 # spent 24.8ms making 1 call to Markdent::Parser::BEGIN@12
# spent 24.7ms making 1 call to MooseX::Types::Combine::import |
| 13 | 3 | 202µs | 2 | 1.71ms | # spent 883µs (52+831) within Markdent::Parser::BEGIN@13 which was called:
# once (52µs+831µs) by Markdent::Simple::Document::BEGIN@10 at line 13 # spent 883µs making 1 call to Markdent::Parser::BEGIN@13
# spent 831µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 14 | 3 | 182µs | 2 | 1.26ms | # spent 661µs (65+596) within Markdent::Parser::BEGIN@14 which was called:
# once (65µs+596µs) by Markdent::Simple::Document::BEGIN@10 at line 14 # spent 661µs making 1 call to Markdent::Parser::BEGIN@14
# spent 596µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 3 | 143µs | 2 | 515µs | # spent 285µs (55+230) within Markdent::Parser::BEGIN@16 which was called:
# once (55µs+230µs) by Markdent::Simple::Document::BEGIN@10 at line 16 # spent 285µs making 1 call to Markdent::Parser::BEGIN@16
# spent 230µs making 1 call to namespace::autoclean::import |
| 17 | 3 | 168µs | 2 | 54.2ms | # spent 27.1ms (49µs+27.1) within Markdent::Parser::BEGIN@17 which was called:
# once (49µs+27.1ms) by Markdent::Simple::Document::BEGIN@10 at line 17 # spent 27.1ms making 1 call to Markdent::Parser::BEGIN@17
# spent 27.1ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456] |
| 18 | 3 | 157µs | 2 | 38.7ms | # spent 19.4ms (47µs+19.3) within Markdent::Parser::BEGIN@18 which was called:
# once (47µs+19.3ms) by Markdent::Simple::Document::BEGIN@10 at line 18 # spent 19.4ms making 1 call to Markdent::Parser::BEGIN@18
# spent 19.3ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456] |
| 19 | 3 | 3.11ms | 2 | 50.5ms | # spent 25.3ms (48µs+25.3) within Markdent::Parser::BEGIN@19 which was called:
# once (48µs+25.3ms) by Markdent::Simple::Document::BEGIN@10 at line 19 # spent 25.3ms making 1 call to Markdent::Parser::BEGIN@19
# spent 25.3ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456] |
| 20 | |||||
| 21 | 1 | 17µs | 1 | 23.8ms | with 'Markdent::Role::AnyParser'; # spent 23.8ms making 1 call to Moose::with |
| 22 | |||||
| 23 | 1 | 29µs | 2 | 18.0ms | has _block_parser_class => ( # spent 17.6ms making 1 call to Moose::has
# spent 336µs making 1 call to __TYPE__::Markdent::Types::Internal::BlockParserClass |
| 24 | is => 'rw', | ||||
| 25 | isa => BlockParserClass, | ||||
| 26 | init_arg => 'block_parser_class', | ||||
| 27 | default => 'Markdent::Dialect::Standard::BlockParser', | ||||
| 28 | ); | ||||
| 29 | |||||
| 30 | 1 | 21µs | 1 | 14.0ms | has _block_parser => ( # spent 14.0ms making 1 call to Moose::has |
| 31 | is => 'ro', | ||||
| 32 | does => 'Markdent::Role::BlockParser', | ||||
| 33 | lazy => 1, | ||||
| 34 | init_arg => undef, | ||||
| 35 | builder => '_build_block_parser', | ||||
| 36 | ); | ||||
| 37 | |||||
| 38 | 1 | 25µs | 2 | 17.6ms | has _block_parser_args => ( # spent 17.3ms making 1 call to Moose::has
# spent 336µs making 1 call to __TYPE__::HashRef |
| 39 | is => 'rw', | ||||
| 40 | does => HashRef, | ||||
| 41 | init_arg => undef, | ||||
| 42 | ); | ||||
| 43 | |||||
| 44 | 1 | 26µs | 2 | 17.8ms | has _span_parser_class => ( # spent 17.5ms making 1 call to Moose::has
# spent 335µs making 1 call to __TYPE__::Markdent::Types::Internal::SpanParserClass |
| 45 | is => 'rw', | ||||
| 46 | does => SpanParserClass, | ||||
| 47 | init_arg => 'span_parser_class', | ||||
| 48 | default => 'Markdent::Dialect::Standard::SpanParser', | ||||
| 49 | ); | ||||
| 50 | |||||
| 51 | 1 | 26µs | 2 | 17.8ms | has _span_parser_args => ( # spent 17.4ms making 1 call to Moose::has
# spent 333µs making 1 call to __TYPE__::HashRef |
| 52 | is => 'rw', | ||||
| 53 | does => HashRef, | ||||
| 54 | init_arg => undef, | ||||
| 55 | ); | ||||
| 56 | |||||
| 57 | 1 | 16µs | 1 | 14.6ms | has _span_parser => ( # spent 14.6ms making 1 call to Moose::has |
| 58 | is => 'ro', | ||||
| 59 | does => 'Markdent::Role::SpanParser', | ||||
| 60 | lazy => 1, | ||||
| 61 | init_arg => undef, | ||||
| 62 | builder => '_build_span_parser', | ||||
| 63 | ); | ||||
| 64 | |||||
| 65 | sub BUILD { | ||||
| 66 | my $self = shift; | ||||
| 67 | my $args = shift; | ||||
| 68 | |||||
| 69 | $self->_set_classes_for_dialect($args); | ||||
| 70 | |||||
| 71 | my %sp_args; | ||||
| 72 | for my $key ( | ||||
| 73 | grep {defined} | ||||
| 74 | map { $_->init_arg() } | ||||
| 75 | $self->_span_parser_class()->meta()->get_all_attributes() | ||||
| 76 | ) { | ||||
| 77 | |||||
| 78 | $sp_args{$key} = $args->{$key} | ||||
| 79 | if exists $args->{$key}; | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | $sp_args{handler} = $self->handler(); | ||||
| 83 | |||||
| 84 | $self->_set_span_parser_args(\%sp_args); | ||||
| 85 | |||||
| 86 | my %bp_args; | ||||
| 87 | for my $key ( | ||||
| 88 | grep {defined} | ||||
| 89 | map { $_->init_arg() } | ||||
| 90 | $self->_block_parser_class()->meta()->get_all_attributes() | ||||
| 91 | ) { | ||||
| 92 | |||||
| 93 | $bp_args{$key} = $args->{$key} | ||||
| 94 | if exists $args->{$key}; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | $bp_args{handler} = $self->handler(); | ||||
| 98 | $bp_args{span_parser} = $self->_span_parser(); | ||||
| 99 | |||||
| 100 | $self->_set_block_parser_args(\%bp_args); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | sub _set_classes_for_dialect { | ||||
| 104 | my $self = shift; | ||||
| 105 | my $args = shift; | ||||
| 106 | |||||
| 107 | my $dialect = delete $args->{dialect} | ||||
| 108 | or return; | ||||
| 109 | |||||
| 110 | for my $pair ( | ||||
| 111 | map { [ $_, $self->_class_name_for_dialect( $dialect, $_ ) ] } | ||||
| 112 | qw( block_parser span_parser ) ) { | ||||
| 113 | |||||
| 114 | my ( $thing, $class ) = @{$pair}; | ||||
| 115 | |||||
| 116 | my $loaded; | ||||
| 117 | try { | ||||
| 118 | Class::MOP::load_class($class); | ||||
| 119 | $loaded = 1; | ||||
| 120 | } | ||||
| 121 | catch { | ||||
| 122 | |||||
| 123 | # XXX - This is kind of broken, since a user can typo a dialect | ||||
| 124 | # and that will just get ignored. | ||||
| 125 | die $_ unless $_ =~ /Can't locate/; | ||||
| 126 | }; | ||||
| 127 | |||||
| 128 | next unless $loaded; | ||||
| 129 | |||||
| 130 | if ( exists $args->{ $thing . '_class' } ) { | ||||
| 131 | die | ||||
| 132 | "You specified a dialect ($dialect) which has its own $thing class" | ||||
| 133 | . " and you also specified an explicit $thing class." | ||||
| 134 | . " You cannot specify both when creating a Markdent::Parser."; | ||||
| 135 | } | ||||
| 136 | |||||
| 137 | my $meth = '_set_' . $thing . '_class'; | ||||
| 138 | $self->$meth($class); | ||||
| 139 | } | ||||
| 140 | } | ||||
| 141 | |||||
| 142 | sub _class_name_for_dialect { | ||||
| 143 | my $self = shift; | ||||
| 144 | my $dialect = shift; | ||||
| 145 | my $type = shift; | ||||
| 146 | |||||
| 147 | my $suffix = join q{}, map {ucfirst} split /_/, $type; | ||||
| 148 | |||||
| 149 | if ( $dialect =~ /::/ ) { | ||||
| 150 | return join '::', $dialect, $suffix; | ||||
| 151 | } | ||||
| 152 | else { | ||||
| 153 | return join '::', 'Markdent::Dialect', $dialect, $suffix; | ||||
| 154 | } | ||||
| 155 | } | ||||
| 156 | |||||
| 157 | sub _build_block_parser { | ||||
| 158 | my $self = shift; | ||||
| 159 | |||||
| 160 | return $self->_block_parser_class()->new( $self->_block_parser_args() ); | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | sub _build_span_parser { | ||||
| 164 | my $self = shift; | ||||
| 165 | |||||
| 166 | return $self->_span_parser_class()->new( $self->_span_parser_args() ); | ||||
| 167 | } | ||||
| 168 | |||||
| 169 | sub parse { | ||||
| 170 | my $self = shift; | ||||
| 171 | my ($text) = validated_list( | ||||
| 172 | \@_, | ||||
| 173 | markdown => { isa => Str }, | ||||
| 174 | ); | ||||
| 175 | |||||
| 176 | $self->_clean_text(\$text); | ||||
| 177 | |||||
| 178 | $self->_send_event('StartDocument'); | ||||
| 179 | |||||
| 180 | $self->_block_parser()->parse_document(\$text); | ||||
| 181 | |||||
| 182 | $self->_send_event('EndDocument'); | ||||
| 183 | |||||
| 184 | return; | ||||
| 185 | } | ||||
| 186 | |||||
| 187 | sub _clean_text { | ||||
| 188 | my $self = shift; | ||||
| 189 | my $text = shift; | ||||
| 190 | |||||
| 191 | ${$text} =~ s/\r\n?/\n/g; | ||||
| 192 | ${$text} .= "\n" | ||||
| 193 | unless substr( ${$text}, -1, 1 ) eq "\n"; | ||||
| 194 | |||||
| 195 | return; | ||||
| 196 | } | ||||
| 197 | |||||
| 198 | 1 | 60µs | 2 | 26.2ms | __PACKAGE__->meta()->make_immutable(); # spent 26.1ms making 1 call to Class::MOP::Class::make_immutable
# spent 104µs making 1 call to Markdent::Parser::meta |
| 199 | |||||
| 200 | 1 | 175µs | 1; | ||
| 201 | |||||
| 202 | # ABSTRACT: A markdown parser | ||||
| 203 | |||||
| - - | |||||
| 206 | =pod | ||||
| 207 | |||||
| - - | |||||
| 310 | 1 | 87µs | 1 | 17.7ms | __END__ # spent 17.7ms making 1 call to B::Hooks::EndOfScope::__ANON__[B/Hooks/EndOfScope.pm:26] |