File Coverage

blib/lib/Data/Microformat/hCard/organization.pm
Criterion Covered Total %
statement 36 36 100.0
branch 8 10 80.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 4 4 100.0
total 57 60 95.0


line stmt bran cond sub pod time code
1             package Data::Microformat::hCard::organization;
2 14     14   1657 use base qw(Data::Microformat);
  14         22  
  14         1374  
3              
4 14     14   177 use strict;
  14         46  
  14         387  
5 14     14   80 use warnings;
  14         32  
  14         5879  
6              
7             our $VERSION = "0.04";
8              
9 26     26 1 158 sub class_name { "org" }
10 30     30 1 115 sub plural_fields { qw() }
11 30     30 1 127 sub singular_fields { qw(organization_name organization_unit) }
12              
13             sub from_tree
14             {
15 9     9 1 15 my $class = shift;
16 9         14 my $tree = shift;
17            
18 9         59 $tree = $tree->look_down("class", qr/(^|\s)org($|\s)/);
19            
20 9 50       406 return unless $tree;
21            
22 9         53 my $object = Data::Microformat::hCard::organization->new;
23 9         38 $object->{_no_dupe_keys} = 1;
24 9         35 my @bits = $tree->content_list;
25            
26 9         66 foreach my $bit (@bits)
27             {
28 25 100       55 if (ref($bit) eq "HTML::Element")
29             {
30 12 50       31 next unless $bit->attr('class');
31 12         123 my @types = split(" ", $bit->attr('class'));
32 12         287 foreach my $type (@types)
33             {
34 12         34 $type =~ s/\-/\_/;
35 12         63 $type = $class->_trim($type);
36 12         30 my @cons = $bit->content_list;
37 12         89 my $data = $class->_trim($cons[0]);
38 12 100 66     38 if ($bit->tag eq "abbr" && $bit->attr('title'))
39             {
40 2         34 $data = $class->_trim($bit->attr('title'));
41             }
42 12         136 $object->$type($data);
43             }
44             }
45             else
46             {
47 13         58 $bit = $class->_trim($bit);
48 13 100       56 if (length $bit > 0)
49             {
50 3         27 $object->organization_name($bit);
51             }
52             }
53             }
54 9         18 $object->{_no_dupe_keys} = 0;
55 9         36 return $object;
56             }
57              
58             1;
59              
60             __END__