TABOO/Data/Plurals/Categories.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 97 CC 6 SCAR 27.8
CC
6
Cov
0%
load
42.0
new
2.0
BEGIN
2.0
CRAP 16.1
1 package AxKit::App::TABOO::Data::Plurals::Categories;
2 use strict;
3 use warnings;
4 use Carp;
5  
6 use Data::Dumper;
7 use AxKit::App::TABOO::Data;
8 use AxKit::App::TABOO::Data::Category;
9 use AxKit::App::TABOO::Data::Plurals;
10  
11  
12 use vars qw/@ISA/;
13 @ISA = qw(AxKit::App::TABOO::Data::Plurals);
14  
15 use DBI;
16 use Exception::Class::DBI;
17  
18  
19 our $VERSION = '0.21';
20  
21 AxKit::App::TABOO::Data::Plurals::Categories->dbtable("categories");
22 AxKit::App::TABOO::Data::Plurals::Categories->dbfrom("categories");
23  
24  
25 =head1 NAME
26  
27 AxKit::App::TABOO::Data::Plurals::Categories - Data objects to handle multiple Categories in TABOO
28  
29 =head1 DESCRIPTION
30  
31 Often, you want to retrieve many different categories from the data
32 store, for example all of a certain type. This is a typical situation
33 where this class shoule be used.
34  
35 =head2 Methods
36  
37 =over
38  
39 =item C<new(@dbconnectargs)>
40  
41 The constructor. Nothing special.
42  
43 =cut
44  
45 sub new {
46 my $that = shift;
47 my $class = ref($that) || $that;
48 my $self = {
49 ENTRIES => [], # Internally, some methods finds it useful that the entries are stored in a array of this name.
50 DBCONNECTARGS => \@_,
51 XMLPREFIX => undef,
52 XMLELEMENT => undef,
53 XMLNS => undef,
54 };
55 bless($self, $class);
56 return $self;
57 }
58  
59  
60 =item C<load(what =E<gt> fields, limit =E<gt> {key =E<gt> value, [...]}, orderby =E<gt> fields, entries =E<gt> number, withcontent =E<gt> boolean)>
61  
62 This load method can be used to retrieve a number of entries from a
63 data store. It uses named parameters, the first C<what> is used to
64 determine which fields to retrieve. It is a string consisting of a
65 commaseparated list of fields, as specified in the data store. The
66 C<limit> argument is to be used to determine which records to
67 retrieve, these will be combined by logical AND. You may also supply a
68 C<orderby> argument, which is an expression used to determine the
69 order of entries returned. Finally, you may supply a C<entries>
70 argument, which is the maximum number of entries to retrieve. If a
71 boolean C<onlycontent> is set to true, it will check if there are
72 articles or stories in the C<categ> category types, and return only
73 those.
74  
75 It will retrieve the data, and then call C<populate()> for each of the
76 records retrieved to ensure that the plural data objects actually
77 consists of an array of L<AxKit::App::TABOO::Data::Category>s. But it
78 calls the internal C<_load()>-method to do the hard work (and that's
79 in the parent class).
80  
81 If there is no data that corresponds to the given arguments, this
82 method will return C<undef>.
83  
84 =cut
85  
86  
87 sub load {
88 my ($self, %args) = @_;
89 my $data = $self->_load(%args); # Does the hard work
90 return undef unless (@{$data});
91 my $dbh = DBI->connect($self->dbconnectargs());
92 my @hassomething;
93 if ($args{'onlycontent'}) {
94 my $tmp = $dbh->selectcol_arrayref("SELECT catname FROM categories JOIN articlecats ON (categories.id =articlecats.cat_id) WHERE type='categ' UNION SELECT primcat FROM stories WHERE NOT sectionid='subqueue'");
95 if (ref($tmp) eq 'ARRAY') {
96 @hassomething = @{$tmp};
97 } else {
98 return undef;
99 }
100 }
101 my $anything = 0;
102 foreach my $entry (@{$data}) {
103 next if (($args{'onlycontent'}) && (! grep(/^${$entry}{'catname'}$/, @hassomething)));
104 my $cat = AxKit::App::TABOO::Data::Category->new($self->dbconnectargs());
105 $cat->populate($entry);
106 $cat->onfile;
107 $self->Push($cat);
108 $anything = 1;
109 }
110 return undef unless $anything;
111 return $self;
112 }
113  
114 =back
115  
116 =head1 BUGS/TODO
117  
118 Not anything particular at the moment...
119  
120  
121 =head1 FORMALITIES
122  
123 See L<AxKit::App::TABOO>.
124  
125 =cut
126  
127 1;
128  
129