TABOO/Provider/Article.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 89 CC 3 SCAR 10.4
CC
3
Cov
0%
get_strref
6.0
exists
6.0
init
2.0
CRAP 2.8
1 package Apache::AxKit::Provider::Article;
2  
3 use DBI;
4 use Data::Dumper;
5 use strict;
6 use XML::LibXML;
7  
8 our $VERSION = '0.18_01';
9  
10 =head1 NAME
11  
12 AxKit::App::TABOO::Provider::Article - Article Provider for TABOO
13  
14 =head1 BUGS/TODO
15  
16 Right now, this Provider hardly works at all. It encounters some nasty
17 problems, apparently within XML::LibXML that makes the apache process
18 segfault. I really can't find a way around it. The important functions
19 that this provider should perform is currently implemented in XSP, and
20 those familiar with TABOO's design goals will be aware that this is
21 not something I take lightly.
22  
23 =cut
24  
25  
26 use vars qw/@ISA/;
27 @ISA = ('Apache::AxKit::Provider');
28  
29 use Apache;
30 use Apache::AxKit::Exception;
31 use Apache::AxKit::Provider;
32 use AxKit::App::TABOO;
33 use AxKit;
34  
35 # sub: Init
36 # Here we do some initialization stuff.
37 sub init {
38 my $self = shift;
39 my $r = $self->apache_request();
40
41 AxKit::Debug(10, "Request object: " . $r->as_string);
42 AxKit::Debug(8, "[uri] Article Provider using URI " . $r->uri);
43
44 $self->{uri} = $r->uri;
45 ($self->{primcat}, $self->{filename}) = $r->uri =~ m|/articles/(.*?)/(.*?)$|;
46
47 AxKit::Debug(9, "Filename is: " . $self->{filename});
48 AxKit::Debug(9, "Primary category is: " . $self->{primcat});
49
50 $self->{metadata} = AxKit::App::TABOO::Data::Article->new();
51 $self->{metadata}->load(limit => { filename => $self->{filename},
52 primcat => $self->{primcat}});
53 return $self;
54 }
55  
56 sub get_strref {
57 my $self = shift;
58 unless (defined($self->{metadata})) {
59 throw Apache::AxKit::Exception::Retval(
60 return_code => 404,
61 -text => "Article does not exist");
62 }
63 my $doc = XML::LibXML::Document->new();
64 my $rootel = $doc->createElement('taboo');
65 # $rootel->setAttribute('type', 'article');
66 # $rootel->setAttribute('origin', 'Article');
67 $doc->setDocumentElement($rootel);
68 $self->{metadata}->write_xml($doc, $rootel);
69 return $doc->toString(1);
70 }
71
72 # sub: get_fh
73 # we don't want to handle files, so we just throw an exception here.
74 sub get_fh {
75 throw Apache::AxKit::Exception::IO(
76 -text => "Can't get fh for DBI filehandle"
77 );
78 }
79  
80  
81 # sub: mtime
82 # This should return the modification time of the resource, for simplicity here we decrement it everytime we are called
83  
84 sub mtime {
85 my $self=shift;
86 return time();
87 }
88  
89 # sub: process
90  
91 sub process {
92 my $self = shift;
93 return $self->{exists};
94 }
95  
96 # sub: key
97 # should return a unique identifier for the resource.
98  
99 sub key {
100 my $self = shift;
101 return $self->{primcat} . '/' . $self->{filename} ;
102 }
103  
104 # sub: exists
105 # should return 1 only if the resource actually exists.
106 # Checking if the underlying file exists.
107 sub exists {
108 my $self = shift;
109 # my $fullfile = $self->{basedir} . $self->{primcat} . '/' . $self->{filename} . '/main';
110 # my $status = -e $fullfile;
111 $self->{exists} = (defined($self->{metadata})) ?1:0;
112 # if (!$status)
113 # {
114 # AxKit::Debug(5, "file '$fullfile' does not exist or is not readable");
115 # }
116 return $self->{exists};
117 }
118  
119  
120 1;
121  
122  
123