TABOO/Data/Category.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 73 CC 2 SCAR 9.8
CC
2
Cov
0%
load_name
6.0
new
2.0
BEGIN
2.0
CRAP 2.7
1 package AxKit::App::TABOO::Data::Category;
2 use strict;
3 use warnings;
4 use Carp;
5 use Encode;
6  
7 use Data::Dumper;
8 use AxKit::App::TABOO::Data;
9 use vars qw/@ISA/;
10 @ISA = qw(AxKit::App::TABOO::Data);
11  
12 use DBI;
13 use Exception::Class::DBI;
14  
15  
16 our $VERSION = '0.18';
17  
18  
19 =head1 NAME
20  
21 AxKit::App::TABOO::Data::Category - Category Data objects for TABOO
22  
23 =head1 SYNOPSIS
24  
25 use AxKit::App::TABOO::Data::Category;
26 $cat = AxKit::App::TABOO::Data::Category->new(@dbconnectargs);
27 $cat->load(what => '*', limit => {catname => 'kitten'});
28  
29  
30 =head1 DESCRIPTION
31  
32 It is often convenient to lump articles together in categories. People do that to organize subjects that interest them, find things that are related and so on. In the TABOO framework, the intention is to use several types of categories, but they are conceptually similar, and so, stored together.
33  
34 =cut
35  
36 AxKit::App::TABOO::Data::Category->elementorder("catname, name, type, uri, description");
37 AxKit::App::TABOO::Data::Category->dbfrom("categories");
38 AxKit::App::TABOO::Data::Category->dbtable("categories");
39 AxKit::App::TABOO::Data::Category->dbprimkey("catname");
40  
41 =head1 METHODS
42  
43 This class implements only one method, in addition to the constructor, the rest is inherited from L<AxKit::App::TABOO::Data>.
44  
45 =over
46  
47 =item C<new(@dbconnectargs)>
48  
49 The constructor. Nothing special.
50  
51  
52 =item C<load_name($catname)>
53  
54 This is an ad hoc method to retrieve the full name of a category, and it takes a C<$catname> key to identify the category to retrieve. It will return a string with the name, but it will also populate the corresponding data fields of the object. You may therefore call C<write_xml> on the object afterwards and have markup for the categoryname and name.
55  
56 =cut
57  
58 sub load_name {
59 my $self = shift;
60 my $catname = shift;
61 my $dbh = DBI->connect($self->dbconnectargs());
62 my $sth = $dbh->prepare("SELECT name FROM categories WHERE catname=?");
63 $sth->execute($catname);
64 my @data = $sth->fetchrow_array;
65 if (@data) {
66 ${$self}{'ONFILE'} = 1;
67 }
68 ${$self}{'name'} = Encode::decode_utf8(join('', @data));
69 ${$self}{'catname'} = $catname;
70 return ${$self}{'name'};
71 }
72  
73 =back
74  
75 =head1 STORED DATA
76  
77 The data is stored in named fields, and for certain uses, it is good to know them. If you want to subclass this class, you might want to use the same names, see the documentation of L<AxKit::APP::TABOO::Data> for more about this. These are the names of the stored data of this class:
78  
79 =over
80  
81 =item * catname
82  
83 A simple word containing a unique name and identifier for the category.
84  
85 =item * name
86  
87 An expanded name intended for human consumption.
88  
89 =item * type
90  
91 TABOO (is intended to) recognize several types of categories, for different uses. The content of type should be one of several 5-character strings:
92  
93 =over
94  
95 =item * categ - the basic category, for a hacker website, for example "Perl", "Apache" etc. However, it is the intention that categ should be a controlled vocabulary, i.e. your article should fit in one or more categories, and you have to choose from those provided to you.
96  
97 =item * frees - Sort of like a category, but Free Subjects. If it doesn't really fit in any of the categories, you should be free to specify something, and this may also be useful in lumping things together in an ad hoc way.
98  
99 =item * angle - People write articles about the same subject but see it from different angles. For example, an anthropologist will view hackerdom from a different angle than a programmer.
100  
101 =item * stsec - Stories that are managed by the Story data objects go in different sections, and we store them here.
102  
103 =back
104  
105 This may be extended, and this may not even be the place to document it in the future.
106  
107 =item * uri
108  
109 In the Semantic Web you'd like to identify things and their relationships with URIs. So, we try to record an URI for everything.
110  
111 =item * description
112  
113 A longer description of a category, intended as an explanation to a human what kind of things belong in that category.
114  
115 =back
116  
117  
118  
119 =head1 XML representation
120  
121 The C<write_xml()> method, implemented in the parent class, can be
122 used to create an XML representation of the data in the object. The
123 above names will be used as element names. The C<xmlelement()>,
124 C<xmlns()> and C<xmlprefix()> methods can be used to set the name of
125 the root element, the namespace URI and namespace prefix
126 respectively. Usually, it doesn't make sense to change the default
127 namespace or prefix, that are
128  
129 =over
130  
131 =item * C<http://www.kjetil.kjernsmo.net/software/TABOO/NS/Category/Output>
132  
133 =item * C<category>
134  
135 =back
136  
137 However, the root element may change depending on what kind of category we have. The default is C<category>.
138  
139 =cut
140  
141 sub new {
142 my $that = shift;
143 my $class = ref($that) || $that;
144 my $self = {
145 catname => undef,
146 name => undef,
147 type => undef,
148 uri => undef,
149 description => undef,
150 DBCONNECTARGS => \@_,
151 XMLELEMENT => 'category',
152 XMLPREFIX => 'cat',
153 XMLNS => 'http://www.kjetil.kjernsmo.net/software/TABOO/NS/Category/Output',
154 ONFILE => undef,
155 };
156 bless($self, $class);
157 return $self;
158 }
159  
160  
161 =head1 FORMALITIES
162  
163 See L<AxKit::App::TABOO>.
164  
165 =cut
166  
167 1;
168  
169