Toader/Entry/Cache.pm

filter: Statementstmt 7.7% 26 / 334 Branchbran 0.0% 0 / 114 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 8 / 18 Podpod 100% 10 / 10 totaltotal 9.2% 44 / 476 CC 58 SCAR 41.3
CC
58
Cov
6%
updateEntry
132.0
init
90.0
updateAll
90.0
CRAP 62.4
« Toader/Entry/Manage.pm ↑ Summary Toader/Config.pm »
1 package Toader::Entry::Cache;
2  
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Toader::isaToaderDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Toader::pathHelper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Toader::Entry::Manage;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Toader::Entry::Helper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Toader::Entry::Cache - Misc helper methods for entries.
15  
16 =head1 VERSION
17  
18 Version 0.0.0
19  
20 =cut
21  
22 7 our $VERSION = '0.0.0';
23  
24 =head1 METHODS
25  
26 =head2 new
27  
28 This initializes this object.
29  
30 On argument is required and it is a L<Toader> object.
31  
32 my $foo = Toader::Entry::Cache->new( $toader );
33 if($foo->error){
34 warn('error: '.$foo->error.":".$foo->errorString);
35 }
36  
37 =cut
38  
39 0 ▶sub new{
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
40 0 my $toader=$_[1];
41  
42 0 my $self={
43 error=>undef,
44 errorString=>'',
45 dir=>undef,
46 edir=>undef,
47 isatd=>Toader::isaToaderDir->new,
48 VCSusable=>0,
49 toader=>undef,
50 errorExtra=>{
51 flags=>{
52 1=>'noToaderObj',
53 2=>'notAtoaderObj',
54 3=>'manageNewErrored',
55 4=>'getVCSerrored',
56 5=>'VCSusableErrored',
57 6=>'noDirSpecified',
58 7=>'notAtoaderDir',
59 8=>'noDirSet',
60 9=>'noEntrySpecified',
61 10=>'notAtoaderEntryObj',
62 11=>'DBIinitErrored',
63 12=>'DBIdoErr',
64 13=>'manageSetDirErrored',
65 14=>'manageListErrored',
66 15=>'manageReadErrored',
67 16=>'noEntryNameSpecified',
68 },
69 },
70 };
71 0 bless $self;
72  
73 #if we have a Toader object, reel it in
74 0 ▶ if ( ! defined( $toader ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $toader) 0 0 0
75 0 $self->{perror}=1;
76 0 $self->{error}=1;
77 0 $self->{errorString}='No Toader object specified';
78 0 $self->warn;
79 0 return $self;
80 }
81 0 ▶ if ( ref( $toader ) ne "Toader" ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $toader ne "Toader") 0 0 0
82 0 $self->{perror}=1;
83 0 $self->{error}=2;
84 0 $self->{errorString}='The object specified is a "'.ref($toader).'"';
85 0 $self->warn;
86 0 return $self;
87 }
88 0 $self->{toader}=$toader;
89  
90 #init the helper
91 0 $self->{helper}=Toader::Entry::Helper->new( $self->{toader} );
92 0 ▶ if ( $self->{helper}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"helper"}->error) 0 0 0
93 0 $self->{perror}=1;
94 0 $self->{error}=18;
95 $self->{errorString}='Failed to initialize Toader::Entry::Helper.'.
96 0 'error="'.$self->{helper}->error.'" errorString="'.$self->{helper}->errorString.'"';
97 0 $self->warn;
98 0 return $self;
99 }
100  
101 #gets the Toader::VCS object
102 0 $self->{vcs}=$self->{toader}->getVCS;
103 0 ▶ if ( $toader->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($toader->error) 0 0 0
104 0 $self->{perror}=1;
105 0 $self->{error}=4;
106 $self->{errorString}='Toader->getVCS errored. error="'.
107 0 $self->{toader}->error.'" errorString="'.$self->{toader}->errorString.'"';
108 0 $self->warn;
109 0 return $self;
110 }
111
112 #checks if VCS is usable
113 0 $self->{VCSusable}=$self->{vcs}->usable;
114 0 ▶ if ( $self->{vcs}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vcs"}->error) 0 0 0
115 0 $self->{perror}=1;
116 0 $self->{error}=5;
117 $self->{errorString}='Toader::VCS->usable errored. error="'.
118 0 $self->{toader}->error.'" errorString="'.$self->{toader}->errorString.'"';
119 0 $self->warn;
120 0 return $self;
121 }
122  
123 0 return $self;
124 }
125  
126 =head2 cachefile
127  
128 This returns the SQLite file that contains the cache for this directory.
129  
130 my $cacheFile=$foo->cachefile;
131 if($foo->error){
132 warn('error: '.$foo->error.":".$foo->errorString);
133 }
134  
135 =cut
136  
137 0 ▶sub cachefile{
Subroutine cachefile: not called CC=3 SCAR=24.8
Pod documented
138 0 my $self=$_[0];
139  
140 #blank any previous errors
141 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
142 0 return undef;
143 }
144  
145 #make sure a directory is defined
146 0 ▶ if ( ! defined( $self->{dir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
147 0 $self->{error}=8;
148 0 $self->{errorString}='No dir set';
149 0 $self->warn;
150 0 return undef;
151 }
152  
153 0 return $self->{cachefile};
154 }
155  
156 =head2 connect
157  
158 This connect to the SQLite database containing
159 the cache and returns the database handler.
160  
161 my $dbh=$foo->connect;
162 if($foo->error){
163 warn('error: '.$foo->error.":".$foo->errorString);
164 }
165  
166  
167 =cut
168  
169 0 ▶sub connect{
Subroutine connect: not called CC=6 SCAR=37.4
Pod documented
170 0 my $self=$_[0];
171  
172 #blank any previous errors
173 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
174 0 return undef;
175 }
176  
177 #make sure a directory is defined
178 0 ▶ if ( ! defined( $self->{dir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
179 0 $self->{error}=8;
180 0 $self->{errorString}='No dir set';
181 0 $self->warn;
182 0 return undef;
183 }
184  
185 #return the stored dbh if it exists
186 0 ▶ if ( defined( $self->{dbh} ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dbh"}) 0 0 0
187 0 return $self->{dbh};
188 }
189  
190 #connect the database if needed
191 0 my $dbh=DBI->connect( 'dbi:SQLite:dbname='.$self->cachefile, "", "" );
192 0 ▶ if ( ! defined( $dbh ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dbh) 0 0 0
193 0 $self->{error}=11;
194 0 $self->{errorString}='DBI->connect failed. err="'.DBI::err.'" errstr="'.DBI::errstr.'"';
195 0 $self->warn;
196 0 return undef;
197 }
198 0 $self->{dbh}=$dbh;
199  
200 #init... checks if it needs initialized...
201 0 $self->init;
202 0 ▶ if ( $self->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
203 0 $self->warnString('Need to init the cache, but failed');
204 0 return undef;
205 }
206
207 0 return $dbh;
208 }
209  
210 =head2 deleteEntry
211  
212 Deletes a specified entry from the cache.
213  
214 One argument is taken and the is the name of the entry.
215  
216 $foo->deleteEntry( $entryName );
217 if($foo->error){
218 warn('error: '.$foo->error.":".$foo->errorString);
219 }
220  
221 =cut
222  
223 0 ▶sub deleteEntry{
Subroutine deleteEntry: not called CC=6 SCAR=37.4
Pod documented
224 0 my $self=$_[0];
225 0 my $entryName=$_[1];
226  
227 #blank any previous errors
228 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
229 0 return undef;
230 }
231  
232 #make sure we have an entry
233 0 ▶ if ( ! defined ( $entryName ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $entryName) 0 0 0
234 0 $self->{error}=16;
235 0 $self->{errorString}='No entryName specified';
236 0 $self->warn;
237 0 return undef;
238 }
239  
240 #gets the DBH to use
241 0 my $dbh=$self->connect;
242 0 ▶ if ( $self->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
243 0 $self->warnString('Failed to get the DBH via $self->connect');
244 0 return undef;
245 }
246  
247 #delete it if it exists
248 0 my $sql='DELETE FROM Entries WHERE entry=?;';
249 0 $dbh->do( $sql, undef, $entryName );
250 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
251 0 $self->{error}=12;
252 0 $self->{errorString}='DBI->do("'.$sql.'") failed. err="'.
253 DBI::err.'" errstr="'.DBI::errstr.'"';
254 0 $self->warn;
255 0 return undef;
256 }
257  
258 #remove any old tags
259 0 $sql='DELETE FROM Tags WHERE entry=?;';
260 0 $dbh->do( $sql, undef, $entryName );
261 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
262 0 $self->{error}=12;
263 0 $self->{errorString}='DBI->do("'.$sql.'") failed. err="'.
264 DBI::err.'" errstr="'.DBI::errstr.'"';
265 0 $self->warn;
266 0 return undef;
267 }
268  
269 0 return 1;
270 }
271  
272 =head2 disconnect
273  
274 This disconnect from the SQLite database containing
275 the cache and returns the database handler.
276  
277 my $dbh=$foo->connect;
278 if($foo->error){
279 warn('error: '.$foo->error.":".$foo->errorString);
280 }
281  
282 =cut
283  
284 0 ▶sub disconnect{
Subroutine disconnect: not called CC=4 SCAR=30.0
Pod documented
285 0 my $self=$_[0];
286  
287 #blank any previous errors
288 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
289 0 return undef;
290 }
291  
292 #make sure a directory is defined
293 0 ▶ if ( ! defined( $self->{dir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
294 0 $self->{error}=8;
295 0 $self->{errorString}='No dir set';
296 0 $self->warn;
297 0 return undef;
298 }
299  
300 #if there is no stored dbh, we are good
301 0 ▶ if ( ! defined( $self->{dbh} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
302 0 return 1;
303 }
304  
305 #disconnects and removes the handler
306 0 $self->{dbh}->disconnect;
307 0 delete( $self->{dbh} );
308  
309 0 return 1;
310 }
311  
312 =head2 init
313  
314 This checks if the cache needs initialized for the directory. If it
315 does need initialized it will do so.
316  
317 $foo->init
318 if($foo->error){
319 warn('error: '.$foo->error.":".$foo->errorString);
320 }
321  
322 =cut
323  
324 0 ▶sub init{
Subroutine init: not called CC=9 SCAR=45.0
Pod documented
325 0 my $self=$_[0];
326  
327 #blank any previous errors
328 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
329 0 return undef;
330 }
331  
332 #make sure a directory is defined
333 0 ▶ if ( ! defined( $self->{dir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
334 0 $self->{error}=8;
335 0 $self->{errorString}='No dir set';
336 0 $self->warn;
337 0 return undef;
338 }
339  
340 #cache exists
341 0 ▶ if ( -f $self->{cachefile} ){
Branch: 1 branch
BranchTrueFalseTotal
if (-f $self->{"cachefile"}) 0 0 0
342 0 return 1;
343 }
344  
345 #if VCS is not usable, stop here
346 0 ▶ if ( ! $self->{VCSusable} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"VCSusable"}) 0 0 0
347 0 return 1;
348 }
349  
350 #initialize it as it has not been created
351 0 $self->reinit;
352 0 ▶ if ( $self->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
353 0 $self->warnString( 'Failed to call reinit' );
354 0 return undef;
355 }
356  
357 #if it is under VCS, we have nothing to do
358 0 my $underVCS=$self->{vcs}->underVCS( $self->cachefile );
359 0 ▶ if ( $self->{vcs}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vcs"}->error) 0 0 0
360 0 $self->{error}=17;
361 $self->{errorString}='Toader::VCS->underVCS errored. error="'.
362 0 $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"';
363 0 $self->warn;
364 0 return undef;
365 }
366 0 ▶ if ( $underVCS ){
Branch: 1 branch
BranchTrueFalseTotal
if ($underVCS) 0 0 0
367 0 return 1;
368 }
369  
370 #add it as if we reach here it is not under VCS and VCS is being used
371 0 $self->{vcs}->add( $self->cachefile );
372 0 ▶ if ( $self->{vcs}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vcs"}->error) 0 0 0
373 0 $self->{error}=18;
374 $self->{errorString}='Toader::VCS->add errored. error="'.
375 0 $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"';
376 0 $self->warn;
377 0 return undef;
378 }
379  
380 0 return 1;
381 }
382  
383 =head2 reinit
384  
385 Re-initializes the SQLite database. This will
386 connect to it, drop the tables, and then recreate
387 the tables.
388  
389 $foo->reinit;
390 if($foo->error){
391 warn('error: '.$foo->error.":".$foo->errorString);
392 }
393  
394 =cut
395  
396 0 ▶sub reinit{
Subroutine reinit: not called CC=8 SCAR=42.8
Pod documented
397 0 my $self=$_[0];
398  
399 #blank any previous errors
400 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
401 0 return undef;
402 }
403  
404 #make sure a directory is defined
405 0 ▶ if ( ! defined( $self->{dir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
406 0 $self->{error}=8;
407 0 $self->{errorString}='No dir set';
408 0 $self->warn;
409 0 return undef;
410 }
411  
412 #connects to the database
413 0 my $dbh=$self->connect;
414 0 ▶ if ( $self->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
415 0 $self->warnString();
416 0 return undef;
417 }
418  
419 #drops the Tags table
420 0 my $do="DROP TABLE IF EXISTS Tags;";
421 0 $dbh->do( $do );
422 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
423 0 $self->{error}=12;
424 0 $self->{errorString}='DBI->do("'.$do.'") failed. err="'.
425 DBI::err.'" errstr="'.DBI::errstr.'"';
426 0 $self->warn;
427 0 return undef;
428 }
429  
430 #create the Tags table
431 0 $do="CREATE TABLE Tags( entry TEXT, tag TEXT );";
432 0 $dbh->do( $do );
433 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
434 0 $self->{error}=12;
435 0 $self->{errorString}='DBI->do("'.$do.'") failed. err="'.
436 DBI::err.'" errstr="'.DBI::errstr.'"';
437 0 $self->warn;
438 0 return undef;
439 }
440  
441 #drop the Entries table
442 0 $do="DROP TABLE IF EXISTS Entries;";
443 0 $dbh->do( $do );
444 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
445 0 $self->{error}=12;
446 0 $self->{errorString}='DBI->do("'.$do.'") failed. err="'.
447 DBI::err.'" errstr="'.DBI::errstr.'"';
448 0 $self->warn;
449 0 return undef;
450 }
451  
452 #create the Entries table
453 0 $do="CREATE TABLE Entries( entry TEXT PRIMARY KEY, renderer TEXT, title TEXT, summary TEXT, From TEXT, publish INT );";
454 0 $dbh->do( $do );
455 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
456 0 $self->{error}=12;
457 0 $self->{errorString}='DBI->do("'.$do.'") failed. err="'.
458 DBI::err.'" errstr="'.DBI::errstr.'"';
459 0 $self->warn;
460 0 return undef;
461 }
462  
463 0 return 1;
464 }
465  
466 =head2 setDir
467  
468 This sets the directory to operate on.
469  
470 One argument is required. It is the directory to use.
471  
472 $foo->setDir($directory);
473 if($foo->error){
474 warn('error: '.$foo->error.":".$foo->errorString);
475 }
476  
477 =cut
478  
479 0 ▶sub setDir{
Subroutine setDir: not called CC=5 SCAR=34.0
Pod documented
480 0 my $self=$_[0];
481 0 my $directory=$_[1];
482  
483 #blank any previous errors
484 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
485 0 return undef;
486 }
487  
488 #error if no directory is specified
489 0 ▶ if (!defined( $directory )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $directory) 0 0 0
490 0 $self->{error}=6;
491 0 $self->{errorString}='No directory specified';
492 0 $self->warn;
493 0 return undef;
494 }
495  
496 #cleans up the naming
497 0 my $pathHelper=Toader::pathHelper->new( $directory );
498 0 $directory=$pathHelper->cleanup( $directory );
499  
500 #make sure it is a Toader directory
501 0 my $tdc=Toader::isaToaderDir->new;
502 0 my $isaToaderDir=$tdc->isaToaderDir($directory);
503 0 ▶ if ( ! $isaToaderDir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isaToaderDir) 0 0 0
504 0 $self->{error}=7;
505 0 $self->{errorString}='Not a Toader directory according to Toader::isaToaderDir->isaToaderDir ';
506 0 $self->warn;
507 0 return undef;
508 }
509  
510 #delete the dbh if needed
511 0 ▶ if ( defined( $self->{dbh} ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dbh"}) 0 0 0
512 0 $self->{dbh}->disconnect;
513 0 delete( $self->{dbh} );
514 }
515  
516 #save the directory
517 0 $self->{dir}=$directory;
518
519 #sets the cache file
520 0 $self->{cachefile}=$self->{helper}->entryDirectory.'/cache.sqlite';
521  
522 0 return 1;
523 }
524  
525 =head2 updateAll
526  
527 Updates the cache for all entries in that directory.
528  
529 $foo->updateAll;
530 if ( $foo->error ){
531 warn( 'error:'.$foo->error.':'.$foo->errorString );
532 }
533  
534 =cut
535  
536 0 ▶sub updateAll{
Subroutine updateAll: not called CC=9 SCAR=45.0
Pod documented
537 0 my $self=$_[0];
538  
539 #blank any previous errors
540 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
541 0 return undef;
542 }
543  
544 #make sure a directory is defined
545 0 ▶ if ( ! defined( $self->{dir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
546 0 $self->{error}=8;
547 0 $self->{errorString}='No dir set';
548 0 $self->warn;
549 0 return undef;
550 }
551  
552 #gets the entry manager
553 0 my $em=Toader::Entry::Manage->new( $self->{toader} );
554 0 ▶ if ( $em->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($em->error) 0 0 0
555 0 $self->{error}=3;
556 0 $self->{errorString}='Failed to invoke Toader::Entry::Manage->new. error="'.$em->error.
557 '" errorFlag="'.$em->errorFlag.'" errorString="'.$em->errorString.'"';
558 0 $self->warn;
559 0 return undef;
560 }
561  
562 #sets the directory for the manager
563 0 $em->setDir( $self->{dir} );
564 0 ▶ if ( $em->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($em->error) 0 0 0
565 0 $self->{error}=13;
566 0 $self->{errorString}='Failed to invoke Toader::Entry::Manage->setDir. error="'.$em->error.
567 '" errorFlag="'.$em->errorFlag.'" errorString="'.$em->errorString.'"';
568 0 $self->warn;
569 0 return undef;
570 }
571  
572 #gets a list of all the entries
573 0 my @entries=$em->list;
574 0 ▶ if ( $em->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($em->error) 0 0 0
575 0 $self->{error}=14;
576 0 $self->{errorString}='Failed to invoke Toader::Entry::Manage->list. error="'.$em->error.
577 '" errorFlag="'.$em->errorFlag.'" errorString="'.$em->errorString.'"';
578 0 $self->warn;
579 0 return undef;
580 }
581  
582 #go through each one
583 0 my $int=0;
584 0 ▶ while ( defined $entries[$int] ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entries[$int]) 0 0 0
585 #gets the entry
586 0 my $entry=$em->read( $entries[$int] );
587 0 ▶ if ( $em->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($em->error) 0 0 0
588 0 $self->{error}=15;
589 0 $self->{errorString}='Failed to invoke Toader::Entry::Manage->read. error="'.$em->error.
590 '" errorFlag="'.$em->errorFlag.'" errorString="'.$em->errorString.'"';
591 0 $self->warn;
592 0 return undef;
593 }
594  
595 #updates the cache for the entry
596 0 $self->updateEntry( $entry );
597 0 ▶ if ( $self->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
598 0 $self->warnString('updateEntry errored for "'.$entries[$int].'"');
599 return undef
600 0 }
601  
602 0 $int++;
603 }
604  
605 0 return 1;
606 }
607  
608 =head2 updateEntry
609  
610 Updates the cache for the passed entry.
611  
612 One argument is taken and that is the Toader::Entry object that
613 the cache is being updated for.
614  
615 $foo->updateEntry( $entry );
616 if($foo->error){
617 warn('error: '.$foo->error.":".$foo->errorString);
618 }
619  
620 =cut
621  
622 0 ▶sub updateEntry{
Subroutine updateEntry: not called CC=11 SCAR=48.8
Pod documented
623 0 my $self=$_[0];
624 0 my $entry=$_[1];
625  
626 #blank any previous errors
627 0 ▶ if (!$self->errorblank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
628 0 return undef;
629 }
630  
631 #make sure we have an entry
632 0 ▶ if ( ! defined ( $entry ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $entry) 0 0 0
633 0 $self->{error}=9;
634 0 $self->{errorString}='No entry specified';
635 0 $self->warn;
636 0 return undef;
637 }
638  
639 #make sure we have a Toader::Entry object
640 0 ▶ if ( ref( $entry ) ne "Toader::Entry" ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry ne "Toader::Entry") 0 0 0
641 0 $self->{error}=10;
642 0 $self->{errorString}='Not a Toader::Entry object';
643 0 $self->warn;
644 0 return undef;
645 }
646  
647 #make sure a directory is defined
648 0 ▶ if ( ! defined( $self->{dir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
649 0 $self->{error}=8;
650 0 $self->{errorString}='No dir set';
651 0 $self->warn;
652 0 return undef;
653 }
654  
655 0 my $entryID=$entry->entryNameGet;
656 0 my $renderer=$entry->rendererGet;
657 0 my $title=$entry->titleGet;
658 0 my $summary=$entry->summaryGet;
659 0 my $From=$entry->fromGet;
660 0 my $publish=$entry->publishGet;
661 0 my @tags=$entry->tagsGet;
662  
663 #gets the DBH to use
664 0 my $dbh=$self->connect;
665 0 ▶ if ( $self->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
666 0 $self->warnString('Failed to get the DBH via $self->connect');
667 0 return undef;
668 }
669  
670 #delete it if it exists
671 0 my $sql='DELETE FROM Entries WHERE entry=?;';
672 0 $dbh->do( $sql, undef, $entryID );
673 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
674 0 $self->{error}=12;
675 0 $self->{errorString}='DBI->do("'.$sql.'") failed. err="'.
676 DBI::err.'" errstr="'.DBI::errstr.'"';
677 0 $self->warn;
678 0 return undef;
679 }
680
681 #adds it
682 0 $sql='INSERT INTO Entries ( entry, renderer, title, summary, From, publish ) values ( ?, ?, ?, ?, ?, ? );';
683 0 $dbh->do( $sql, undef, $entryID, $renderer, $title, $summary, $From, $publish );
684 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
685 0 $self->{error}=12;
686 0 $self->{errorString}='DBI->do("'.$sql.'") failed. err="'.
687 DBI::err.'" errstr="'.DBI::errstr.'"';
688 0 $self->warn;
689 0 return undef;
690 }
691  
692 #remove any old tags
693 0 $sql='DELETE FROM Tags WHERE entry=?;';
694 0 $dbh->do( $sql, undef, $entryID );
695 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
696 0 $self->{error}=12;
697 0 $self->{errorString}='DBI->do("'.$sql.'") failed. err="'.
698 DBI::err.'" errstr="'.DBI::errstr.'"';
699 0 $self->warn;
700 0 return undef;
701 }
702  
703 #processes each tag
704 0 my $int=0;
705 0 ▶ while( defined( $tags[ $int ] ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tags[$int]) 0 0 0
706 #add the tag for that entry
707 0 $sql='INSERT INTO Tags ( entry, tag ) VALUES ( ?, ? );';
708 0 $dbh->do( $sql, undef, $entryID, $tags[ $int ] );
709 0 ▶ if ( $dbh->err ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) 0 0 0
710 0 $self->{error}=12;
711 0 $self->{errorString}='DBI->do("'.$sql.'") failed. err="'.
712 DBI::err.'" errstr="'.DBI::errstr.'"';
713 0 $self->warn;
714 0 return undef;
715 }
716  
717 0 $int++;
718 }
719  
720 0 return 1;
721 }
722  
723 =head1 ERROR CODES/Flags
724  
725 =head2 1, noToaderObj
726  
727 The object supplied for the L<Toader> object.
728  
729 =head2 2, notAtoaderObj
730  
731 The supplies object is not a L<Toader> object.
732  
733 =head2 3, manageNewErrored
734  
735 L<Toader::Entry::Manage>->new errored.
736  
737 =head2 4, getVCSerrored
738  
739 Failed to get L<Toader::VCS> object.
740  
741 =head2 5, VCSusableErrored
742  
743 L<Toader::VCS>->usable errored.
744  
745 =head2 6, noDirSpecified
746  
747 Nothing was passed as a directory.
748  
749 =head2 7, notAtoaderDir
750  
751 The specified directory is not a L<Toader> directory.
752  
753 =head2 8, noDirSet
754  
755 No dir has been set yet.
756  
757 =head2 9, noEntrySpecified
758  
759 No entry was specified to processes. This needs to be a L<Toader::Entry> object.
760  
761 =head2 10, notAtoaderEntryObj
762  
763 Not a L<Toader::Entry> object.
764  
765 =head2 11, DBIinitErrored
766  
767 Failed to initialize the SQLite database via
768 L<DBI>->connect.
769  
770 =head2 12, DBIdoErr
771  
772 Error with L<DBI>->do.
773  
774 =head2 13, manageSetDirErrored
775  
776 Failed when calling L<Toader::Entry::Manage>->setDir.
777  
778 =head2 14, manageListErrored
779  
780 Failed when calling L<Toader::Entry::Manage>->list.
781  
782 =head2 15, manageReadErrored
783  
784 Failed when calling L<Toader::Entry::Manage>->read.
785  
786 =head2 16, noEntryNameSpecified
787  
788 No entryName was specified to processes. This id different from noEntrySpecified
789 as noEntrySpecified requires a L<Toader::Entry> object and this just requires a
790 entry name.
791  
792 =head2 17, underVCS errored
793  
794 L<Toader::VCS>->underVCS errored.
795  
796 =head2 18, VCSaddErrored
797  
798 L<Toader::VCS>->add errored.
799  
800 =head1 AUTHOR
801  
802 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
803  
804 =head1 BUGS
805  
806 Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through
807 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll
808 automatically be notified of progress on your bug as I make changes.
809  
810 =head1 SUPPORT
811  
812 You can find documentation for this module with the perldoc command.
813  
814 perldoc Toader::Entry::Cache
815  
816  
817 You can also look for information at:
818  
819 =over 4
820  
821 =item * RT: CPAN's request tracker
822  
823 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader>
824  
825 =item * AnnoCPAN: Annotated CPAN documentation
826  
827 L<http://annocpan.org/dist/Toader>
828  
829 =item * CPAN Ratings
830  
831 L<http://cpanratings.perl.org/d/Toader>
832  
833 =item * Search CPAN
834  
835 L<http://search.cpan.org/dist/Toader/>
836  
837 =back
838  
839  
840 =head1 ACKNOWLEDGEMENTS
841  
842  
843 =head1 LICENSE AND COPYRIGHT
844  
845 Copyright 2014 Zane C. Bowers-Hadley.
846  
847 This program is free software; you can redistribute it and/or modify it
848 under the terms of either: the GNU General Public License as published
849 by the Free Software Foundation; or the Artistic License.
850  
851 See http://dev.perl.org/licenses/ for more information.
852  
853 =cut
854  
855 7 1; # End of Toader::Entry::Cache
« Toader/Entry/Manage.pm ↑ Summary Toader/Config.pm »