Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/darwin-2level/HTML/Parser.pm |
Statements | Executed 14 statements in 922µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 13µs | 26µs | BEGIN@9 | HTML::Parser::
1 | 1 | 1 | 7µs | 36µs | BEGIN@10 | HTML::Parser::
0 | 0 | 0 | 0s | 0s | __ANON__[:54] | HTML::Parser::
0 | 0 | 0 | 0s | 0s | __ANON__[:60] | HTML::Parser::
0 | 0 | 0 | 0s | 0s | init | HTML::Parser::
0 | 0 | 0 | 0s | 0s | netscape_buggy_comment | HTML::Parser::
0 | 0 | 0 | 0s | 0s | new | HTML::Parser::
0 | 0 | 0 | 0s | 0s | parse_file | HTML::Parser::
0 | 0 | 0 | 0s | 0s | text | HTML::Parser::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package HTML::Parser; | ||||
2 | |||||
3 | # Copyright 1996-2009, Gisle Aas. | ||||
4 | # Copyright 1999-2000, Michael A. Chase. | ||||
5 | # | ||||
6 | # This library is free software; you can redistribute it and/or | ||||
7 | # modify it under the same terms as Perl itself. | ||||
8 | |||||
9 | 2 | 27µs | 2 | 39µs | # spent 26µs (13+13) within HTML::Parser::BEGIN@9 which was called:
# once (13µs+13µs) by Perl::Tidy::HtmlWriter::BEGIN@2 at line 9 # spent 26µs making 1 call to HTML::Parser::BEGIN@9
# spent 13µs making 1 call to strict::import |
10 | 2 | 506µs | 2 | 65µs | # spent 36µs (7+29) within HTML::Parser::BEGIN@10 which was called:
# once (7µs+29µs) by Perl::Tidy::HtmlWriter::BEGIN@2 at line 10 # spent 36µs making 1 call to HTML::Parser::BEGIN@10
# spent 29µs making 1 call to vars::import |
11 | |||||
12 | 1 | 600ns | $VERSION = "3.71"; | ||
13 | |||||
14 | 1 | 300ns | require HTML::Entities; | ||
15 | |||||
16 | 1 | 800ns | require XSLoader; | ||
17 | 1 | 379µs | 1 | 371µs | XSLoader::load('HTML::Parser', $VERSION); # spent 371µs making 1 call to XSLoader::load |
18 | |||||
19 | sub new | ||||
20 | { | ||||
21 | my $class = shift; | ||||
22 | my $self = bless {}, $class; | ||||
23 | return $self->init(@_); | ||||
24 | } | ||||
25 | |||||
26 | |||||
27 | sub init | ||||
28 | { | ||||
29 | my $self = shift; | ||||
30 | $self->_alloc_pstate; | ||||
31 | |||||
32 | my %arg = @_; | ||||
33 | my $api_version = delete $arg{api_version} || (@_ ? 3 : 2); | ||||
34 | if ($api_version >= 4) { | ||||
35 | require Carp; | ||||
36 | Carp::croak("API version $api_version not supported " . | ||||
37 | "by HTML::Parser $VERSION"); | ||||
38 | } | ||||
39 | |||||
40 | if ($api_version < 3) { | ||||
41 | # Set up method callbacks compatible with HTML-Parser-2.xx | ||||
42 | $self->handler(text => "text", "self,text,is_cdata"); | ||||
43 | $self->handler(end => "end", "self,tagname,text"); | ||||
44 | $self->handler(process => "process", "self,token0,text"); | ||||
45 | $self->handler(start => "start", | ||||
46 | "self,tagname,attr,attrseq,text"); | ||||
47 | |||||
48 | $self->handler(comment => | ||||
49 | sub { | ||||
50 | my($self, $tokens) = @_; | ||||
51 | for (@$tokens) { | ||||
52 | $self->comment($_); | ||||
53 | } | ||||
54 | }, "self,tokens"); | ||||
55 | |||||
56 | $self->handler(declaration => | ||||
57 | sub { | ||||
58 | my $self = shift; | ||||
59 | $self->declaration(substr($_[0], 2, -1)); | ||||
60 | }, "self,text"); | ||||
61 | } | ||||
62 | |||||
63 | if (my $h = delete $arg{handlers}) { | ||||
64 | $h = {@$h} if ref($h) eq "ARRAY"; | ||||
65 | while (my($event, $cb) = each %$h) { | ||||
66 | $self->handler($event => @$cb); | ||||
67 | } | ||||
68 | } | ||||
69 | |||||
70 | # In the end we try to assume plain attribute or handler | ||||
71 | while (my($option, $val) = each %arg) { | ||||
72 | if ($option =~ /^(\w+)_h$/) { | ||||
73 | $self->handler($1 => @$val); | ||||
74 | } | ||||
75 | elsif ($option =~ /^(text|start|end|process|declaration|comment)$/) { | ||||
76 | require Carp; | ||||
77 | Carp::croak("Bad constructor option '$option'"); | ||||
78 | } | ||||
79 | else { | ||||
80 | $self->$option($val); | ||||
81 | } | ||||
82 | } | ||||
83 | |||||
84 | return $self; | ||||
85 | } | ||||
86 | |||||
87 | |||||
88 | sub parse_file | ||||
89 | { | ||||
90 | my($self, $file) = @_; | ||||
91 | my $opened; | ||||
92 | if (!ref($file) && ref(\$file) ne "GLOB") { | ||||
93 | # Assume $file is a filename | ||||
94 | local(*F); | ||||
95 | open(F, "<", $file) || return undef; | ||||
96 | binmode(F); # should we? good for byte counts | ||||
97 | $opened++; | ||||
98 | $file = *F; | ||||
99 | } | ||||
100 | my $chunk = ''; | ||||
101 | while (read($file, $chunk, 512)) { | ||||
102 | $self->parse($chunk) || last; | ||||
103 | } | ||||
104 | close($file) if $opened; | ||||
105 | $self->eof; | ||||
106 | } | ||||
107 | |||||
108 | |||||
109 | sub netscape_buggy_comment # legacy | ||||
110 | { | ||||
111 | my $self = shift; | ||||
112 | require Carp; | ||||
113 | Carp::carp("netscape_buggy_comment() is deprecated. " . | ||||
114 | "Please use the strict_comment() method instead"); | ||||
115 | my $old = !$self->strict_comment; | ||||
116 | $self->strict_comment(!shift) if @_; | ||||
117 | return $old; | ||||
118 | } | ||||
119 | |||||
120 | # set up method stubs | ||||
121 | sub text { } | ||||
122 | 1 | 1µs | *start = \&text; | ||
123 | 1 | 200ns | *end = \&text; | ||
124 | 1 | 200ns | *comment = \&text; | ||
125 | 1 | 100ns | *declaration = \&text; | ||
126 | 1 | 100ns | *process = \&text; | ||
127 | |||||
128 | 1 | 5µs | 1; | ||
129 | |||||
130 | __END__ |