SIOC.pm

filter: Statementstmt 58.9% 43 / 73 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 10 / 16 Podpod 100% 4 / 4 totaltotal 57.5% 57 / 99 CC 5 SCAR 13.4
CC
5
Cov
54%
export_rdf
12.0
_init_template
6.0
set_template_vars
6.0
CRAP 3.8
↑ Summary SIOC/Exporter.pm »
1 ###########################################################
2 # SIOC
3 # Base class for the SIOC ontology
4 ###########################################################
5 #
6 # $Id: SIOC.pm 22 2008-03-21 18:01:41Z geewiz $
7 #
8  
9 package SIOC;
10  
11 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 15 ▶use version; our $VERSION = qv(1.0.0);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 15 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 15 ▶use Template::Provider::FromDATA;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 15 ▶use Data::Dumper qw( Dumper );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 15 ▶use MooseX::AttributeHelpers;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # singleton hash of Template::Provider for the SIOC classes
25 15 my %template_provider;
26  
27 ### required attributes
28  
29 15 has 'id' => (
30 isa => 'Str',
31 is => 'rw',
32 required => 1,
33 );
34 15 has 'name' => (
35 isa => 'Str',
36 is => 'rw',
37 required => 1,
38 );
39 15 has 'url' => (
40 isa => 'Str',
41 is => 'rw',
42 required => 1,
43 );
44
45 ### optional attributes
46  
47 15 has 'description' => (
48 isa => 'Str',
49 is => 'rw',
50 );
51 15 has 'comment' => (
52 isa => 'Str',
53 is => 'rw',
54 );
55 15 has 'topics' => (
56 isa => 'ArrayRef[Str]',
57 metaclass => 'Collection::Array',
58 is => 'rw',
59 provides => {
60 'push' => 'add_topic',
61 },
62 );
63 15 has 'feed' => (
64 isa => 'ArrayRef[Str]',
65 metaclass => 'Collection::Array',
66 is => 'rw',
67 provides => {
68 'push' => 'add_feed'
69 },
70 );
71 15 has 'links' => (
72 isa => 'ArrayRef[Str]',
73 metaclass => 'Collection::Array',
74 is => 'rw',
75 provides => {
76 'push' => 'add_link'
77 },
78 );
79 15 has 'export_url' => (
80 isa => 'Str',
81 is => 'rw',
82 );
83  
84 ### internal attributes
85  
86 has '_template_vars' => (
87 isa => 'HashRef',
88 metaclass => 'Collection::Hash',
89 is => 'rw',
90 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 15 provides => {
92 'set' => 'set_template_var',
93 },
94 );
95
96 ### methods
97  
98 0 ▶sub _init_template {
Subroutine _init_template: not called CC=2 SCAR=17.9
99 0 my ($self) = @_;
100  
101 # get template provider
102 0 my $class_name = ref $self;
103 0 ▶ if (! exists $template_provider{$class_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $template_provider{$class_name}) 0 0 0
104 # create T::Provider for this class
105 0 $template_provider{$class_name}
106 = Template::Provider::FromDATA->new({
107 CLASSES => $class_name,
108 })
109 }
110 0 my $provider = $template_provider{$class_name};
111
112 # create new Template object
113 0 my $template = Template->new({
114 LOAD_TEMPLATES => [
115 $provider,
116 ]
117 });
118  
119 0 return $template;
120 }
121  
122 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
123 0 my ($self) = @_;
124
125 0 my $type = ref $self;
126 0 $type =~ s/SIOC:://xms;
127 0 $type =~ tr/A-Z/a-z/;
128
129 0 return $type;
130 }
131  
132 0 ▶sub set_template_vars {
Subroutine set_template_vars: not called CC=2 SCAR=17.9
Pod documented
133 0 my ($self, $vars) = @_;
134
135 0 foreach my $varname (keys %{$vars}) {
136 0 $self->set_template_var($varname => $vars->{$varname});
137 }
138
139 0 return 1;
140 }
141  
142 0 ▶sub fill_template {
Subroutine fill_template: not called CC=1 SCAR=6.9
Pod documented
143 0 my ($self) = @_;
144  
145 0 $self->set_template_vars({
146 export_url => $self->export_url,
147 id => $self->id,
148 name => $self->name,
149 url => $self->url,
150 description => $self->description,
151 comment => $self->comment
152 });
153
154 0 return 1;
155 }
156  
157 0 ▶sub export_rdf {
Subroutine export_rdf: not called CC=3 SCAR=24.8
Pod documented
158 0 my ($self) = @_;
159
160 0 ▶ if (! defined $self->export_url) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->export_url) 0 0 0
161 0 croak "Object not registered with SIOC::Exporter!\n";
162 }
163
164 0 my $template = $self->_init_template();
165 0 $self->fill_template();
166
167 0 my $output;
168 0 ▶ $template->process('rdfoutput', $self->_template_vars, \$output)
Branch: 1 branch
BranchTrueFalseTotal
$template->process("rdfoutput", $self->_template_vars, \$output) or croak($template->error) 0 0 0
169 || croak $template->error();
170 0 $output =~ s/\s+$//xmsg;
171
172 0 return $output;
173 }
174  
175 15 1;
176 __DATA__
↑ Summary SIOC/Exporter.pm »