| 1 | ########################################################### | ||||||||||
| 2 | # SIOC::Exporter | ||||||||||
| 3 | # Exporter class for the SIOC ontology | ||||||||||
| 4 | ########################################################### | ||||||||||
| 5 | # | ||||||||||
| 6 | # $Id: Exporter.pm 21 2008-03-21 17:45:07Z geewiz $ | ||||||||||
| 7 | # | ||||||||||
| 8 | |||||||||||
| 9 | package SIOC::Exporter; | ||||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | use version; our $VERSION = qv(1.0.0); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use MooseX::AttributeHelpers; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | # singleton Template::Provider for this class | ||||||||||
| 21 | 2 | my $template_provider = Template::Provider::FromDATA->new({ | |||||||||
| 22 | CLASSES => __PACKAGE__, | ||||||||||
| 23 | }); | ||||||||||
| 24 | |||||||||||
| 25 | ### required attributes | ||||||||||
| 26 | |||||||||||
| 27 | 2 | has 'host' => ( | |||||||||
| 28 | isa => 'Str', | ||||||||||
| 29 | is => 'rw', | ||||||||||
| 30 | required => 1, | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | ### optional attributes | ||||||||||
| 34 | |||||||||||
| 35 | has 'encoding' => ( | ||||||||||
| 36 | isa => 'Str', | ||||||||||
| 37 | is => 'ro', | ||||||||||
| 38 | 0 | ▶ | default => sub { 'utf-8' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | 2 | ); | |||||||||
| 40 | has 'generator' => ( | ||||||||||
| 41 | isa => 'Str', | ||||||||||
| 42 | is => 'ro', | ||||||||||
| 43 | 0 | ▶ | default => sub { 'perl-SIOC' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 44 | 2 | ); | |||||||||
| 45 | has 'export_email' => ( | ||||||||||
| 46 | isa => 'Str', | ||||||||||
| 47 | is => 'ro', | ||||||||||
| 48 | 0 | ▶ | default => sub { 0 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 2 | ); | |||||||||
| 50 | |||||||||||
| 51 | ### internal attributes | ||||||||||
| 52 | |||||||||||
| 53 | 2 | has '_object' => ( | |||||||||
| 54 | isa => 'SIOC', | ||||||||||
| 55 | is => 'rw', | ||||||||||
| 56 | ); | ||||||||||
| 57 | has '_url' => ( | ||||||||||
| 58 | isa => 'Str', | ||||||||||
| 59 | is => 'ro', | ||||||||||
| 60 | 0 | ▶ | default => sub { 'http://wiki.sioc.org/...' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 61 | 2 | ); | |||||||||
| 62 | has '_version' => ( | ||||||||||
| 63 | isa => 'Str', | ||||||||||
| 64 | is => 'ro', | ||||||||||
| 65 | 0 | ▶ | default => sub { "$VERSION" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | 2 | ); | |||||||||
| 67 | |||||||||||
| 68 | ### methods | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub _init_template { | ||||||||
|
Subroutine
_init_template: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 0 | my ($self) = @_; | |||||||||
| 72 | |||||||||||
| 73 | # create new Template object | ||||||||||
| 74 | 0 | my $template = Template->new({ | |||||||||
| 75 | LOAD_TEMPLATES => [ | ||||||||||
| 76 | $template_provider, | ||||||||||
| 77 | ] | ||||||||||
| 78 | }); | ||||||||||
| 79 | |||||||||||
| 80 | 0 | return $template; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | sub register_object { | ||||||||
|
Subroutine
register_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 84 | 0 | my ($self, $object) = @_; | |||||||||
| 85 | |||||||||||
| 86 | 0 | my $export_url = $self->object_export_url($object); | |||||||||
| 87 | 0 | $object->export_url($export_url); | |||||||||
| 88 | |||||||||||
| 89 | 0 | return $export_url; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub export_object { | ||||||||
|
Subroutine
export_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 93 | 0 | my ($self, $object) = @_; | |||||||||
| 94 | |||||||||||
| 95 | 0 | $self->_object($object); | |||||||||
| 96 | |||||||||||
| 97 | 0 | return 1; | |||||||||
| 98 | }; | ||||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | sub object_export_url { | ||||||||
|
Subroutine
object_export_url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 101 | 0 | my ($self, $object) = @_; | |||||||||
| 102 | |||||||||||
| 103 | 0 | my $url = sprintf("%s/sioc.pl?class=%s&id=%s", | |||||||||
| 104 | $self->host, | ||||||||||
| 105 | $object->type, | ||||||||||
| 106 | $object->id | ||||||||||
| 107 | ); | ||||||||||
| 108 | |||||||||||
| 109 | 0 | return $url; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | sub output { | ||||||||
|
Subroutine
output: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 113 | 0 | my ($self) = @_; | |||||||||
| 114 | |||||||||||
| 115 | # prepare template engine | ||||||||||
| 116 | 0 | my $template = $self->_init_template(); | |||||||||
| 117 | 0 | my $output; | |||||||||
| 118 | |||||||||||
| 119 | 0 | my $object_rdf = q(); | |||||||||
| 120 | |||||||||||
| 121 | # set object url attribute | ||||||||||
| 122 | 0 | $self->_object->export_url($self->object_export_url($self->_object)); | |||||||||
| 123 | |||||||||||
| 124 | # fill template variables | ||||||||||
| 125 | 0 | my $template_vars = { | |||||||||
| 126 | encoding => $self->encoding, | ||||||||||
| 127 | exporter_url => $self->_url, | ||||||||||
| 128 | exporter_version => $VERSION, | ||||||||||
| 129 | exporter_generator => 'perl-SIOC', | ||||||||||
| 130 | object => $self->_object, | ||||||||||
| 131 | }; | ||||||||||
| 132 | |||||||||||
| 133 | # process template | ||||||||||
| 134 | 0 | my $ok = $template->process('rdfoutput', $template_vars, \$output); | |||||||||
| 135 | 0 | ▶ | if (! $ok) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | croak $template->error(); | |||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 0 | return $output; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 2 | 1; | |||||||||
| 143 | __DATA__ | ||||||||||