Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d17039f0

Von Moritz Bunkus vor mehr als 5 Jahren hinzugefügt

  • ID d17039f09b3c3fc415d5778d954c02d6be5479dc
  • Vorgänger 257207bd
  • Nachfolger fd0bcc7d

Module: Rose::DBx::Cache::Anywhere durch eigene Variante ersetzt

Unterschiede anzeigen:

SL/DB.pm
6 6
use Data::Dumper;
7 7
use English qw(-no_match_vars);
8 8
use Rose::DB;
9
use Rose::DBx::Cache::Anywhere;
9
use SL::DB::Cache;
10 10
use Scalar::Util qw(blessed);
11 11

  
12 12
use base qw(Rose::DB);
13 13

  
14
__PACKAGE__->db_cache_class('Rose::DBx::Cache::Anywhere');
14
__PACKAGE__->db_cache_class('SL::DB::Cache');
15 15
__PACKAGE__->use_private_registry;
16 16

  
17 17
my (%_db_registered);
SL/DB/Cache.pm
1
package SL::DB::Cache;
2

  
3
use strict;
4
use warnings;
5

  
6
use Carp;
7

  
8
use parent qw(Rose::DB::Cache);
9

  
10
sub prepare_db {
11
  my ($self, $db, $entry) = @_;
12

  
13
  if (!$entry->is_prepared) {
14
    # if this a dummy kivitendo dbh, don't try to actually prepare this.
15
    if ($db->type =~ /KIVITENDO_EMPTY/) {
16
      return;
17
    }
18

  
19
    $entry->prepared(1);
20
  }
21

  
22
  if (!$db->dbh->ping) {
23
    $db->dbh(undef);
24
  }
25
}
26

  
27
1;
28

  
29
__END__
30

  
31
=head1 NAME
32

  
33
SL::DB::Cache - database handle caching for kivitendo
34

  
35
=head1 DESCRIPTION
36

  
37
This class provides database cache handling for kivitendo running
38
under FastCGI. It's based on Rose::DBx::Cache::Anywhere.
39

  
40
=head1 METHODS
41

  
42
=head2 prepare_db( I<rose_db>, I<entry> )
43

  
44
Overrides default method to always ping() dbh.
modules/override/Rose/DBx/Cache/Anywhere.pm
1
package Rose::DBx::Cache::Anywhere;
2
use strict;
3
use warnings;
4
use Carp;
5
use base qw( Rose::DB::Cache );
6

  
7
=head1 NAME
8

  
9
Rose::DBx::Cache::Anywhere - get Apache::DBI behaviour without Apache
10

  
11
=head1 DESCRIPTION
12

  
13
This class is used by Rose::DBx::AutoReconnect.
14
The author uses
15
Rose::DB with Catalyst under both the Catalyst dev server and
16
FastCGI and found that the standard Rose::DB::Cache behaviour
17
did not work well with those environments.
18

  
19
=head1 METHODS
20

  
21
=head2 prepare_db( I<rose_db>, I<entry> )
22

  
23
Overrides default method to always ping() dbh if not running
24
under mod_perl.
25

  
26
=cut
27

  
28
sub prepare_db {
29
    my ( $self, $db, $entry ) = @_;
30

  
31
    if ( Rose::DB::Cache::MOD_PERL_1 || Rose::DB::Cache::MOD_PERL_2 ) {
32
        return $self->SUPER::prepare_db( $db, $entry );
33
    }
34

  
35
    if ( !$entry->is_prepared ) {
36
        if ( $entry->created_during_apache_startup ) {
37
            if ( $db->has_dbh ) {
38
                eval { $db->dbh->disconnect };    # will probably fail!
39
                $db->dbh(undef);
40
            }
41

  
42
            $entry->created_during_apache_startup(0);
43
            return;
44
        }
45

  
46
        # if this a dummy kivitendo dbh, don't try to actually prepare this.
47
        if ($db->type =~ /KIVITENDO_EMPTY/) {
48
          return;
49
        }
50

  
51
        $entry->prepared(1);
52
    }
53

  
54
    if ( !$db->dbh->ping ) {
55
        $db->dbh(undef);
56
    }
57
}
58

  
59
1;
60

  
61
__END__
62

  
63
=head1 AUTHOR
64

  
65
Peter Karman, C<< <karman at cpan.org> >>
66

  
67
=head1 BUGS
68

  
69
Please report any bugs or feature requests to
70
C<bug-rose-dbx-autoreconnect at rt.cpan.org>, or through the web interface at
71
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rose-DBx-AutoReconnect>.
72
I will be notified, and then you'll automatically be notified of progress on
73
your bug as I make changes.
74

  
75
=head1 SUPPORT
76

  
77
You can find documentation for this module with the perldoc command.
78

  
79
    perldoc Rose::DBx::AutoReconnect
80

  
81
You can also look for information at:
82

  
83
=over 4
84

  
85
=item * AnnoCPAN: Annotated CPAN documentation
86

  
87
L<http://annocpan.org/dist/Rose-DBx-AutoReconnect>
88

  
89
=item * CPAN Ratings
90

  
91
L<http://cpanratings.perl.org/d/Rose-DBx-AutoReconnect>
92

  
93
=item * RT: CPAN's request tracker
94

  
95
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rose-DBx-AutoReconnect>
96

  
97
=item * Search CPAN
98

  
99
L<http://search.cpan.org/dist/Rose-DBx-AutoReconnect>
100

  
101
=back
102

  
103
=head1 ACKNOWLEDGEMENTS
104

  
105
The Minnesota Supercomputing Institute C<< http://www.msi.umn.edu/ >>
106
sponsored the development of this software.
107

  
108
=head1 COPYRIGHT
109

  
110
Copyright 2008 by the Regents of the University of Minnesota.
111
All rights reserved.
112

  
113
This program is free software; you can redistribute it and/or modify it
114
under the same terms as Perl itself.
115

  
116
=cut

Auch abrufbar als: Unified diff