blib/lib/UR/Object/Type/View/AvailableViews/Xml.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 74 SCAR 40.3
CC
7
Cov
0%
_find_perspectives
42.0
_generate_content
6.0
BEGIN
2.0
CRAP 56.0
1 package UR::Object::Type::View::AvailableViews::Xml;
2  
3 use strict;
4 use warnings;
5  
6 require UR;
7 our $VERSION = "0.46"; # UR $VERSION;
8  
9 class UR::Object::Type::View::AvailableViews::Xml {
10 is => 'UR::Object::View::Default::Xml',
11 has_constant => [
12 perspective => { value => 'available-views' },
13 ],
14 };
15  
16 sub _generate_content {
17 my $self = shift;
18  
19 my $subject = $self->subject;
20 return unless $subject;
21  
22 my $xml_doc = XML::LibXML->createDocument();
23 $self->_xml_doc($xml_doc);
24  
25 my $target_class = $subject->class_name;
26  
27 my %perspectives = $self->_find_perspectives($target_class);
28  
29 my $perspectives = $xml_doc->createElement('perspectives');
30 $xml_doc->setDocumentElement($perspectives);
31  
32 for my $key (sort keys %perspectives) {
33 my $perspective = $perspectives->addChild( $xml_doc->createElement('perspective') );
34 $perspective->addChild( $xml_doc->createAttribute('name', $key) );
35  
36 for my $tool_key (sort keys %{$perspectives{$key}}) {
37 my $toolkit = $perspective->addChild( $xml_doc->createElement('toolkit'));
38 $toolkit->addChild( $xml_doc->createAttribute('name', $tool_key));
39 }
40 }
41  
42 $perspectives->addChild( $xml_doc->createAttribute( 'type', $target_class ));
43  
44 return $xml_doc->toString(1);
45 }
46  
47 sub _find_perspectives {
48 my $self = shift;
49 my $target_class = shift;
50  
51 my %perspectives;
52 for my $class ($target_class, $target_class->inheritance) {
53 next unless $class->isa('UR::Object');
54 my $namespace = $class->__meta__->namespace;
55  
56 my $dir = $class;
57 $dir =~ s!::!/!g;
58 $dir =~ s!^$namespace/!!;
59 $dir .= '/View';
60 my @views = $namespace->_get_class_names_under_namespace($dir);
61  
62 for my $view (@views) {
63 if(my $view_type = UR::Object::Type->get($view)) {
64 next unless $view->isa('UR::Object::View');
65 my $perspective = $view_type->property_meta_for_name('perspective')->default_value;
66 my $toolkit = $view_type->property_meta_for_name('toolkit')->default_value;
67  
68 unless($perspective) {
69 $self->error_message('No perspective set on view class: ' . $view_type->class_name);
70 next;
71 }
72 unless($toolkit) {
73 $self->error_message('No toolkit set on view class: ' . $view_type->class_name);
74 next;
75 }
76  
77 $perspectives{$perspective}{$toolkit}++;
78 }
79 }
80 }
81  
82 return %perspectives;
83 }
84  
85 1;