File: Outlinee.pm

package info (click to toggle)
libhtml-html5-outline-perl 0.006-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 352 kB
  • ctags: 290
  • sloc: perl: 3,573; makefile: 13
file content (113 lines) | stat: -rw-r--r-- 2,012 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package HTML::HTML5::Outline::Outlinee;

use 5.008;
use strict;

our $VERSION = '0.006';

sub new
{
	my ($class, %data) = @_;

	$data{header}   ||= undef;
	$data{parent}   ||= undef;
	$data{elements} ||= [];

	bless { %data }, $class;
}

sub element  { return $_[0]->{element}; }
sub order    { return $_[0]->{document_order}; }
sub outliner { return $_[0]->{outliner}; }
sub sections { return @{ $_[0]->{sections} || [] }; }

sub children
{
	my ($self) = @_;
	return sort { $a->order <=> $b->order } $self->sections;
}

sub to_hashref
{
	my ($self) = @_;

	my $rdf_type = 'Text';
	
	if ($self->element->tagName eq 'figure'
	||  ($self->element->getAttribute('class')||'') =~ /\bfigure\b/)
	{
		$rdf_type = 'Image';
	}
	elsif ($self->element->tagName =~ /^(ul|ol)$/i
	&&     ($self->element->getAttribute('class')||'') =~ /\bxoxo\b/)
	{
		$rdf_type = 'Dataset';
	}

	my $outline_node = {
		class    => 'Outline',
		type     => $rdf_type,
		tag      => $self->element->tagName,
		};
	
	foreach my $section (@{$self->{sections}})
	{
		push @{ $outline_node->{children} }, $section->to_hashref;
	}
	
	return $outline_node;
}

1;


__END__

=head1 NAME

HTML::HTML5::Outline::Outlinee - an element with an independent outline

=head1 DESCRIPTION

Elements like E<lt>blockquoteE<gt> have their own independent outline,
which is nested within the primary outline somewhere.

=head2 Methods

=over

=item * C<< element >>

An L<XML::LibXML::Element> for the outlinee.

=item * C<< order >>

The order of the outlinee relative to sections and other outlinees.

=item * C<< sections >>

Sections of this outlinee.

=item * C<< children >>

Sections of this outlinee, sorted in document order.

=back

=head1 SEE ALSO

L<HTML::HTML5::Outline::Section>,
L<HTML::HTML5::Outline>.

=head1 AUTHOR

Toby Inkster, E<lt>tobyink@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENCE

Copyright (C) 2008-2011 by Toby Inkster

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut