/[Frey]/trunk/lib/Frey/HTML.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 709 - (show annotations)
Wed Dec 3 22:24:18 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 833 byte(s)
Cleanup all attributes from html
1 package Frey::HTML;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6
7 use HTML::TreeBuilder;
8 use Data::Dump qw/dump/;
9
10 =head1 DESCRIPTION
11
12 Cleanup all attributes from html
13
14 =cut
15
16 has 'html' => (
17 is => 'rw',
18 isa => 'Str',
19 required => 1,
20 default => '<b class="remove me">foo</b>',
21 );
22
23 sub cleanup_as_markup {
24 my $self = shift;
25
26 my $html = HTML::TreeBuilder->new;
27
28 $html->parse( $self->html );
29 $html->eof;
30
31 sub _parse {
32 foreach my $element ( @_ ) {
33 if ( blessed $element && $element->isa('HTML::Element') ) {
34 my $tag = $element->tag;
35 my @kids = $element->content_list;
36 warn dump( $tag, @kids );
37 return "<$tag>" . _parse( @kids ) . "</$tag>";
38 } else {
39 # plain text
40 warn dump( $element );
41 return $element;
42 }
43 }
44 }
45
46 my $result = _parse( $html->guts );
47 $html->delete;
48
49 return $result;
50 }
51
52 1;

  ViewVC Help
Powered by ViewVC 1.1.26