File Coverage

blib/lib/Keystone/Resolver/Admin.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             # $Id: Admin.pm,v 1.8 2007-12-13 17:09:03 mike Exp $
2              
3             # This is the only module that needs to be explicitly "use"d by the
4             # HTML::Mason components that make up the sites. It is responsible,
5             # among other things, for "use"ing all the relevant sub-modules.
6              
7             package Keystone::Resolver::Admin;
8 1     1   22228 use strict;
  1         3  
  1         40  
9 1     1   5 use warnings;
  1         1  
  1         26  
10              
11 1     1   1082 use Keystone::Resolver;
  0            
  0            
12              
13              
14             # PRIVATE to admin(), which implements a singleton
15             my $_admin = undef;
16              
17             # Returns an object -- always the same one -- representing the
18             # Keystone Resolver Admin complex-of-web-site as a whole, and through
19             # which global functionality and objects (such as the database handle)
20             # can be accessed.
21             #
22             sub admin {
23             my $class = shift();
24              
25             if (!defined $_admin) {
26             $_admin = bless {
27             resolver => undef,
28             sites => {},
29             }, $class;
30             }
31              
32             return $_admin;
33             }
34              
35              
36             sub resolver {
37             my $this = shift();
38              
39             if (!defined $this->{resolver}) {
40             ### This should be a setting
41             my $loglevel = (
42             # Keystone::Resolver::LogLevel::CHITCHAT |
43             Keystone::Resolver::LogLevel::CACHECHECK |
44             Keystone::Resolver::LogLevel::PARSEXSLT |
45             Keystone::Resolver::LogLevel::DUMPDESCRIPTORS |
46             Keystone::Resolver::LogLevel::DUMPREFERENT |
47             Keystone::Resolver::LogLevel::SHOWGENRE |
48             # Keystone::Resolver::LogLevel::DBLOOKUP |
49             Keystone::Resolver::LogLevel::MKRESULT |
50             # Keystone::Resolver::LogLevel::SQL |
51             Keystone::Resolver::LogLevel::DEREFERENCE |
52             Keystone::Resolver::LogLevel::DISSECT |
53             Keystone::Resolver::LogLevel::RESOLVEID |
54             Keystone::Resolver::LogLevel::CONVERT01 |
55             Keystone::Resolver::LogLevel::HANDLE |
56             Keystone::Resolver::LogLevel::WARNING |
57             0);
58             $this->{resolver} = new Keystone::Resolver(logprefix => "admin",
59             _rw => 1,
60             loglevel => $loglevel);
61             }
62              
63             return $this->{resolver};
64             }
65              
66              
67             # Delegations to the associated resolver
68             sub db { shift()->resolver()->db(@_) }
69              
70              
71             # This method contains the algorithm for determining, based on the
72             # hostname by which the web server is accessed, which if any of the
73             # available sites should be used.
74             #
75             sub hostname2tag {
76             my $this = shift();
77             my($hostname) = @_;
78              
79             $hostname =~ s/^x\.//; # Development versions begin with "x."
80             $hostname =~ s/:\d+$//; # Discard any trailing port-number
81              
82             my $tag;
83             if ($hostname eq "resolver.indexdata.com") {
84             $tag = "id";
85             }
86             else {
87             $tag = $hostname;
88             $tag =~ s/\..*//;
89             }
90              
91             return $tag;
92             }
93              
94              
95             # Returns the site object associated in the admin-object with the
96             # specified tag, creating it if necessary.
97             #
98             sub site {
99             my $this = shift();
100             my($tag) = @_;
101              
102             if (!defined $this->{sites}->{$tag}) {
103             $this->{sites}->{$tag} = $this->db()->site_by_tag($tag);
104             }
105              
106             return $this->{sites}->{$tag};
107             }
108              
109              
110             1;