| 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.07ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 17.3ms | 5.69s | Markdent::Parser::BEGIN@11 |
| 1 | 1 | 1 | 13.1ms | 5.19s | Markdent::Parser::BEGIN@10 |
| 1 | 1 | 1 | 52µs | 52µs | Markdent::Parser::BEGIN@2 |
| 1 | 1 | 1 | 49µs | 28.1ms | Markdent::Parser::BEGIN@19 |
| 1 | 1 | 1 | 47µs | 23.7ms | Markdent::Parser::BEGIN@18 |
| 1 | 1 | 1 | 45µs | 27.4ms | Markdent::Parser::BEGIN@12 |
| 1 | 1 | 1 | 44µs | 255µs | Markdent::Parser::BEGIN@14 |
| 1 | 1 | 1 | 44µs | 892µs | Markdent::Parser::BEGIN@13 |
| 1 | 1 | 1 | 42µs | 23.0ms | Markdent::Parser::BEGIN@17 |
| 1 | 1 | 1 | 40µs | 298µs | Markdent::Parser::BEGIN@16 |
| 1 | 1 | 1 | 38µs | 57µs | Markdent::Parser::BEGIN@6 |
| 1 | 1 | 1 | 38µs | 107µs | Markdent::Parser::BEGIN@7 |
| 1 | 1 | 1 | 24µs | 24µ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 52µs within Markdent::Parser::BEGIN@2 which was called:
# once (52µs+0s) by Markdent::Simple::Document::BEGIN@10 at line 4 | ||||
| 3 | 1 | 28µs | $Markdent::Parser::VERSION = '0.17'; | ||
| 4 | 1 | 74µs | 1 | 52µs | } # spent 52µs making 1 call to Markdent::Parser::BEGIN@2 |
| 5 | |||||
| 6 | 3 | 96µs | 2 | 75µs | # spent 57µs (38+19) within Markdent::Parser::BEGIN@6 which was called:
# once (38µs+19µs) by Markdent::Simple::Document::BEGIN@10 at line 6 # spent 57µs making 1 call to Markdent::Parser::BEGIN@6
# spent 19µs making 1 call to strict::import |
| 7 | 3 | 98µs | 2 | 176µs | # spent 107µs (38+69) within Markdent::Parser::BEGIN@7 which was called:
# once (38µs+69µs) by Markdent::Simple::Document::BEGIN@10 at line 7 # spent 107µs making 1 call to Markdent::Parser::BEGIN@7
# spent 69µs making 1 call to warnings::import |
| 8 | |||||
| 9 | 3 | 94µs | 1 | 24µs | # spent 24µs within Markdent::Parser::BEGIN@9 which was called:
# once (24µs+0s) by Markdent::Simple::Document::BEGIN@10 at line 9 # spent 24µs making 1 call to Markdent::Parser::BEGIN@9 |
| 10 | 3 | 620µs | 1 | 5.19s | # spent 5.19s (13.1ms+5.17) within Markdent::Parser::BEGIN@10 which was called:
# once (13.1ms+5.17s) by Markdent::Simple::Document::BEGIN@10 at line 10 # spent 5.19s making 1 call to Markdent::Parser::BEGIN@10 |
| 11 | 3 | 662µs | 1 | 5.69s | # spent 5.69s (17.3ms+5.67) within Markdent::Parser::BEGIN@11 which was called:
# once (17.3ms+5.67s) by Markdent::Simple::Document::BEGIN@10 at line 11 # spent 5.69s making 1 call to Markdent::Parser::BEGIN@11 |
| 12 | 3 | 164µs | 2 | 54.7ms | # spent 27.4ms (45µs+27.3) within Markdent::Parser::BEGIN@12 which was called:
# once (45µs+27.3ms) by Markdent::Simple::Document::BEGIN@10 at line 12 # spent 27.4ms making 1 call to Markdent::Parser::BEGIN@12
# spent 27.3ms making 1 call to MooseX::Types::Combine::import |
| 13 | 3 | 148µs | 2 | 1.74ms | # spent 892µs (44+848) within Markdent::Parser::BEGIN@13 which was called:
# once (44µs+848µs) by Markdent::Simple::Document::BEGIN@10 at line 13 # spent 892µs making 1 call to Markdent::Parser::BEGIN@13
# spent 848µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 14 | 3 | 110µs | 2 | 466µs | # spent 255µs (44+211) within Markdent::Parser::BEGIN@14 which was called:
# once (44µs+211µs) by Markdent::Simple::Document::BEGIN@10 at line 14 # spent 255µs making 1 call to Markdent::Parser::BEGIN@14
# spent 211µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 3 | 114µs | 2 | 556µs | # spent 298µs (40+258) within Markdent::Parser::BEGIN@16 which was called:
# once (40µs+258µs) by Markdent::Simple::Document::BEGIN@10 at line 16 # spent 298µs making 1 call to Markdent::Parser::BEGIN@16
# spent 258µs making 1 call to namespace::autoclean::import |
| 17 | 3 | 162µs | 2 | 45.9ms | # spent 23.0ms (42µs+22.9) within Markdent::Parser::BEGIN@17 which was called:
# once (42µs+22.9ms) by Markdent::Simple::Document::BEGIN@10 at line 17 # spent 23.0ms making 1 call to Markdent::Parser::BEGIN@17
# spent 22.9ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456] |
| 18 | 3 | 159µs | 2 | 47.3ms | # spent 23.7ms (47µs+23.6) within Markdent::Parser::BEGIN@18 which was called:
# once (47µs+23.6ms) by Markdent::Simple::Document::BEGIN@10 at line 18 # spent 23.7ms making 1 call to Markdent::Parser::BEGIN@18
# spent 23.6ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456] |
| 19 | 3 | 3.09ms | 2 | 56.2ms | # spent 28.1ms (49µs+28.1) within Markdent::Parser::BEGIN@19 which was called:
# once (49µs+28.1ms) by Markdent::Simple::Document::BEGIN@10 at line 19 # spent 28.1ms making 1 call to Markdent::Parser::BEGIN@19
# spent 28.1ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456] |
| 20 | |||||
| 21 | 1 | 16µs | 1 | 41.0ms | with 'Markdent::Role::AnyParser'; # spent 41.0ms making 1 call to Moose::with |
| 22 | |||||
| 23 | 1 | 30µs | 2 | 17.3ms | has _block_parser_class => ( # spent 17.0ms making 1 call to Moose::has
# spent 330µ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 | 18µs | 1 | 13.8ms | has _block_parser => ( # spent 13.8ms 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 | 26µs | 2 | 17.3ms | has _block_parser_args => ( # spent 17.0ms making 1 call to Moose::has
# spent 350µ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.4ms | has _span_parser_class => ( # spent 17.0ms making 1 call to Moose::has
# spent 332µ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 | 24µs | 2 | 17.3ms | has _span_parser_args => ( # spent 17.0ms 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 | 13.9ms | has _span_parser => ( # spent 13.9ms 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 | 26µs | 2 | 22.7ms | __PACKAGE__->meta()->make_immutable(); # spent 22.5ms making 1 call to Class::MOP::Class::make_immutable
# spent 172µ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 | 90µs | 1 | 30.5ms | __END__ # spent 30.5ms making 1 call to B::Hooks::EndOfScope::__ANON__[B/Hooks/EndOfScope.pm:26] |