Changeset 587


Ignore:
Timestamp:
Dec 14, 2004, 6:46:00 PM (17 years ago)
Author:
kake
Message:

Encapsulate config data in OpenGuides::Config.

Location:
trunk
Files:
1 added
44 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r586 r587  
    22use lib "lib";
    33use OpenGuides::Build;
     4use OpenGuides::Config;
    45use Data::Dumper;
    56
    67eval "use Config::Tiny";
    78die "Config::Tiny is required to configure this application.\n" if $@;
    8 
    9 ##### Find out where to install, etc.
    10 
    11 # See if we already have some config variables set.
    12 my $read_config = Config::Tiny->read('wiki.conf');
    13 my %existing_config = $read_config ? %{ $read_config->{_} } : ();
    14 
    15 my @questions = (
    16 { question =>
    17         "What's the name of the database that this site runs on?",
    18   variable => "dbname"
    19 },
    20 { question => "...the database user that can access that database?",
    21   variable => "dbuser"
    22   },
    23 { question => "...the password that they use to access the database?",
    24   variable => "dbpass"
    25   },
    26 { question => "...the machine that the database is hosted on? (blank if local)",
    27   variable => "dbhost"
    28   },
    29 { question => "What do you want the script to be called?",
    30   variable => "script_name",
    31   default  => "wiki.cgi"
    32   },
    33 { question => "What directory should I install it in?",
    34   variable => "install_directory",
    35   default  => "/usr/lib/cgi-bin/openguides/"
    36   },
    37 { question => "What URL does the install directory map to?",
    38   variable => "script_url",
    39   },
    40 { question => "Do you want me to munge a custom lib path into the scripts? "
    41              . "If so, enter it here.  Separate path entries with whitespace:",
    42   variable => "custom_lib_path",
    43   },
    44 { question => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this if you are upgrading)",
    45   variable => "use_plucene",
    46   default  => "y",
    47   type     => "y_n"
    48   },
    49 { question => "What directory can I use to store indexes in for searching? "
    50             . "***NOTE*** This directory must exist and be writeable by the "
    51             . "user that your script will run as.  See README for more on this.",
    52   variable => "indexing_directory",
    53   default  => "/usr/lib/cgi-bin/openguides/indexes/"
    54   },
    55 { question => "Do you want to enable page deletion?",
    56   variable => "enable_page_deletion",
    57   default  => "n",
    58   type     => "y_n"
    59   },
    60 { question => "Please specify a password for the site admin:",
    61   variable => "admin_pass",
    62   default  => "Change this!"
    63   },
    64 { question => "What's the URL of the site's stylesheet?",
    65   variable => "stylesheet_url"
    66   },
    67 { question => "What's the site called? (should be unique)",
    68   variable => "site_name",
    69   default  => "My OpenGuides Site"
    70   },
    71 { question => "Do you want the navigation bar included on the home page?",
    72   variable => "navbar_on_home_page",
    73   default  => "y",
    74   type     => "y_n"
    75   },
    76 { question => "What should the home page of the wiki be called?",
    77   variable => "home_name",
    78   default  => "Home"
    79   },
    80 { question => "How would you describe the site?",
    81   variable => "site_desc",
    82   default  => "A guide to [my city]"
    83   },
    84 { question => "What city is the site based in?",
    85   variable => "default_city",
    86   default  => "London"
    87   },
    88 { question => "What country is the site based in?",
    89   variable => "default_country",
    90   default  => "United Kingdom"
    91   },
    92 { question => "Contact email address for the site administrator?",
    93   variable => "contact_email"
    94   },
    95 { question => "What language will the site be in? (Please give an ISO language code.)",
    96   variable => "default_language",
    97   default  => "en"
    98   },
    99 { question => "What's the name of the node to use for the text formatting rules link?",
    100   variable => "formatting_rules_node",
    101   default  => "Text Formatting Examples"
    102   },
    103 { question => "Make node titles link to node backlinks (C2 style)?",
    104   variable => "backlinks_in_title",
    105   default  => "n",
    106   type     => "y_n"
    107   },
    108 );
    1099
    11010print <<EOF;
     
    11919my $continue = Module::Build->y_n("Continue with install?", "y");
    12020exit 0 unless $continue;
     21
     22my $existing_config = OpenGuides::Config->new( file => "wiki.conf" );
     23
     24my %yn_vars = map { $_ => 1 }
     25   qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title);
    12126
    12227my $skip_config = Module::Build->y_n("Skip OpenGuides configuration?", "n");
     
    13540# It is an ancient Configurer, and he chooseth one of three.
    13641my $dbtype;
    137 my $dbtype_qu = "what type of database do you want the site to run on?  postgres/mysql/sqlite";
     42my $dbtype_qu = $existing_config->dbtype__qu;
    13843if ( $skip_config ) {
    139     $dbtype = $existing_config{dbtype} || "postgres";
     44    $dbtype = $existing_config->dbtype;
    14045} else {
    14146    until ( $dbtype ) {
    142         my $def = $existing_config{dbtype} || "postgres";
     47        my $def = $existing_config->dbtype;
    14348        $dbtype = Module::Build->prompt("\n$dbtype_qu", $def);
    14449        $dbtype = lc($dbtype);
     
    16469                 value    => $dbtype };
    16570
    166 foreach my $qset (@questions) {
    167     my $qu  = $qset->{question};
    168     my $type = $qset->{type} || "";
    169     my $var = $qset->{variable};
    170     my $def = defined $existing_config{$var} ? $existing_config{$var}
    171                                              : $qset->{default};
     71my $install_directory; # used to suggest template paths
     72foreach my $var ( qw(
     73   dbname dbuser dbpass dbhost script_name
     74   install_directory template_path custom_template_path script_url
     75   custom_lib_path use_plucene indexing_directory enable_page_deletion
     76   admin_pass stylesheet_url site_name navbar_on_home_page home_name
     77   site_desc default_city default_country contact_email default_language
     78   formatting_rules_node backlinks_in_title
     79  ) ) {
     80    my $q_method = $var . "__qu";
     81    my $qu  = $existing_config->$q_method;
     82    my $type = $yn_vars{$var} ? "y_n" : "";
     83    my $def = $existing_config->$var;
    17284    my $val = $def;
    17385
     86    # Override dbname question for SQLite only.
    17487    if ( $dbtype eq "sqlite" and $var eq "dbname" ) {
    17588        $qu = "what's the full filename of the SQLite database this site runs on?";
     
    18699    }
    187100
     101    # Make sensible suggestions for template paths if we don't already
     102    # have them stored.  Not really a default, but a useful hint/shortcut.
     103    if ( $var eq "template_path" && !defined $existing_config->$var ) {
     104        $def = $install_directory;
     105        $def .= "/" unless $def =~ m|/$|;
     106        $def .= "templates";
     107    }
     108    if ( $var eq "custom_template_path" && !defined $existing_config->$var ) {
     109        $def = $install_directory;
     110        $def .= "/" unless $def =~ m|/$|;
     111        $def .= "custom-templates";
     112    }
     113
     114    # Here is where we actually ask the questions.
    188115    unless ( $skip_config ) {
    189116        if ( $type eq "y_n" ) {
     
    198125    }
    199126
     127    # Store install_directory so we can use it to suggest template paths.
     128    $install_directory = $val if $var eq "install_directory";
     129
    200130    # Make sure that script_url ends in a /
    201131    if ( $var eq "script_url" and $val !~ /\/$/ ) {
     
    206136                     variable => $var,
    207137                     value    => $val };
    208 
    209     if ( $var eq "install_directory" ) {
    210         push @answers, {
    211             question => "what directory should I install the templates in?",
    212             variable => "template_path",
    213             value    => $val . "/templates" };
    214         push @answers, {
    215             question => "where should I look for custom templates?",
    216             variable => "custom_template_path",
    217             value    => $val . "/custom-templates" };
    218     }
    219138}
    220139
     
    229148if ( $skip_config ) {
    230149    # We default to GB National Grid for historical reasons.
    231     $geo_handler = $existing_config{geo_handler} || 1;
     150    $geo_handler = $existing_config->geo_handler;
    232151} else {
    233152    my $choice;
    234153    until ( $choice ) {
    235         my $def = $existing_config{geo_handler} || 1;
     154        my $def = $existing_config->geo_handler;
    236155        $choice = Module::Build->prompt("\n".$geo_handler_qu, $def);
    237156        $choice =~ s/^\s*//;
     
    252171
    253172if ( $geo_handler eq "3" ) {
    254     my $qu = "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')";
     173    my $qu = $existing_config->ellipsoid__qu;
    255174    my $ellipsoid;
    256175    if ( $skip_config ) {
    257         $ellipsoid = $existing_config{ellipsoid} || "International";
     176        $ellipsoid = $existing_config->ellipsoid;
    258177    } else {
    259         my $def = $existing_config{ellipsoid} || "International";
     178        my $def = $existing_config->ellipsoid;
    260179        $ellipsoid = Module::Build->prompt("\n".$qu, $def);
    261180        $ellipsoid =~ s/^\s*//;
     
    298217        'CGI::Wiki::Plugin::RSS::ModWiki' => '0.06', # for fancy stuff
    299218        'CGI::Wiki::Plugin::RSS::Reader'  => '1.3',  # earlier versions don't support RSS 2.0
     219        'Class::Accessor'                 => 0,
    300220        'Config::Tiny'                    => 0,
    301221        'Data::Dumper'                    => 0,
  • trunk/MANIFEST

    r586 r587  
    1515lib/OpenGuides/Build.pm
    1616lib/OpenGuides/CGI.pm
     17lib/OpenGuides/Config.pm
    1718lib/OpenGuides/RDF.pm
    1819lib/OpenGuides/SuperSearch.pm
  • trunk/PREREQUISITES

    r586 r587  
    1313CGI::Wiki::Plugin::RSS::ModWiki (version 0.06 or later)
    1414CGI::Wiki::Plugin::RSS::Reader (version 1.3 or later)
     15Class::Accessor
    1516Config::Tiny
    1617Data::Dumper
  • trunk/lib/OpenGuides.pm

    r586 r587  
    3535=item B<new>
    3636
     37  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    3738  my $guide = OpenGuides->new( config => $config );
    3839
     
    4647    $self->{wiki} = $wiki;
    4748    $self->{config} = $args{config};
    48     # Default to British National Grid for historical reasons.
    49     my $geo_handler = $self->config->{_}{geo_handler} || 1;
     49    my $geo_handler = $self->config->geo_handler;
    5050    my $locator;
    5151    if ( $geo_handler == 1 ) {
     
    8080=item B<config>
    8181
    82 An accessor, returns the underlying L<Config::Tiny> object.
     82An accessor, returns the underlying L<OpenGuides::Config> object.
    8383
    8484=cut
     
    140140    my $return_output = $args{return_output} || 0;
    141141    my $version = $args{version};
    142     my $id = $args{id} || $self->config->{_}->{home_name};
     142    my $id = $args{id} || $self->config->home_name;
    143143    my $wiki = $self->wiki;
    144144    my $config = $self->config;
     
    152152        $tt_vars{index_value} = $2;
    153153        $tt_vars{"rss_".lc($type)."_url"} =
    154                            $config->{_}{script_name} . "?action=rss;"
     154                           $config->script_name . "?action=rss;"
    155155                           . lc($type) . "=" . lc(CGI->escape($2));
    156156    }
     
    193193                 version       => $node_data{version},
    194194                 node          => $id,
    195                  language      => $config->{_}->{default_language},
     195                 language      => $config->default_language,
    196196               );
    197197
     
    223223                  username_param => CGI->escape($_->{metadata}{username}[0]),
    224224                  edit_type   => CGI->escapeHTML($_->{metadata}{edit_type}[0]),
    225                   url         => "$config->{_}->{script_name}?"
     225                  url         => $config->script_name . "?"
    226226          . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})),
    227227                }
     
    247247                  username_param => CGI->escape($_->{metadata}{username}[0]),
    248248                  edit_type   => CGI->escapeHTML($_->{metadata}{edit_type}[0]),
    249                   url         => "$config->{_}->{script_name}?"
     249                  url         => $config->script_name . "?"
    250250          . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})),
    251251                }
     
    272272        return $output if $return_output;
    273273        print $output;
    274     } elsif ( $id eq $self->config->{_}->{home_name} ) {
     274    } elsif ( $id eq $self->config->home_name ) {
    275275        my @recent = $wiki->list_recent_changes(
    276276            last_n_changes => 10,
     
    281281                         comment       => CGI->escapeHTML($_->{metadata}{comment}[0]),
    282282                         username      => CGI->escapeHTML($_->{metadata}{username}[0]),
    283                          url           => "$config->{_}->{script_name}?"
     283                         url           => $config->script_name . "?"
    284284          . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})) }
    285285                       } @recent;
     
    368368    my $lat = $data{metadata}{latitude}[0];
    369369    my $long = $data{metadata}{longitude}[0];
    370     my $script_url = $self->config->{_}{script_url};
     370    my $script_url = $self->config->script_url;
    371371    print CGI->redirect( $script_url . "supersearch.cgi?lat=$lat;long=$long;distance_in_metres=$metres" );
    372372}
     
    456456            );
    457457            my $name = ucfirst($args{type}) . " $args{value}" ;
    458             my $url = $self->config->{_}->{script_name}
     458            my $url = $self->config->script_name
    459459                      . "?"
    460460                      . ucfirst( $args{type} )
     
    782782
    783783    if ($password) {
    784         if ($password ne $self->config->{_}->{admin_pass}) {
     784        if ($password ne $self->config->admin_pass) {
    785785            return %tt_vars if $return_tt_vars;
    786786            my $output = $self->process_template(
     
    840840sub redirect_to_node {
    841841    my ($self, $node) = @_;
    842     my $script_url = $self->config->{_}->{script_url};
    843     my $script_name = $self->config->{_}->{script_name};
     842    my $script_url = $self->config->script_url;
     843    my $script_name = $self->config->script_name;
    844844    my $formatter = $self->wiki->formatter;
    845845    my $param = $formatter->node_name_to_node_param( $node );
  • trunk/lib/OpenGuides/Build.pm

    r586 r587  
    33use strict;
    44use Module::Build;
     5use OpenGuides::Config;
    56use base 'Module::Build';
    67
     
    1314    die "Config::Tiny is required to set up this application.\n" if $@;
    1415
    15     my $config = Config::Tiny->read("wiki.conf");
     16    my $config = OpenGuides::Config->new( file => "wiki.conf" );
    1617
    1718    # Initialise the database if necessary.
    18     my $dbname = $config->{_}->{dbname};
    19     my $dbuser = $config->{_}->{dbuser};
    20     my $dbpass = $config->{_}->{dbpass};
    21     my $dbhost = $config->{_}->{dbhost};
    22     my $dbtype = $config->{_}->{dbtype};
     19    my $dbname = $config->dbname;
     20    my $dbuser = $config->dbuser;
     21    my $dbpass = $config->dbpass;
     22    my $dbhost = $config->dbhost;
     23    my $dbtype = $config->dbtype;
    2324
    2425    my %cgi_wiki_exts = ( postgres => "Pg",
     
    5152    die "Config::Tiny is required to set up this application.\n" if $@;
    5253
    53     my $config = Config::Tiny->read("wiki.conf");
     54    my $config = OpenGuides::Config->new( file => "wiki.conf" );
    5455
    5556    # Install the scripts where we were told to.
    56     my $install_directory    = $config->{_}->{install_directory};
    57     my $script_name          = $config->{_}->{script_name};
    58     my $template_path        = $config->{_}->{template_path};
    59     my $custom_template_path = $config->{_}->{custom_template_path};
    60     my $custom_lib_path      = $config->{_}->{custom_lib_path};
     57    my $install_directory    = $config->install_directory;
     58    my $script_name          = $config->script_name;
     59    my $template_path        = $config->template_path;
     60    my $custom_template_path = $config->custom_template_path;
     61    my $custom_lib_path      = $config->custom_lib_path;
    6162    my @extra_scripts        = @{ $self->{config}{__extra_scripts} };
    6263    my @templates            = @{ $self->{config}{__templates} };
  • trunk/lib/OpenGuides/CGI.pm

    r586 r587  
    2121Saving preferences in a cookie:
    2222
    23   use Config::Tiny;
    2423  use OpenGuides::CGI;
     24  use OpenGuides::Config;
    2525  use OpenGuides::Template;
    2626  use OpenGuides::Utils;
    2727
    28   my $config = Config::Tiny->read( "wiki.conf" );
     28  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    2929
    3030  my $cookie = OpenGuides::CGI->make_prefs_cookie(
     
    5555Tracking visits to Recent Changes:
    5656
    57   use Config::Tiny;
    5857  use OpenGuides::CGI;
     58  use OpenGuides::Config;
    5959  use OpenGuides::Template;
    6060  use OpenGuides::Utils;
    6161
    62   my $config = Config::Tiny->read( "wiki.conf" );
     62  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    6363
    6464  my $cookie = OpenGuides::CGI->make_recent_changes_cookie(
     
    8585  );
    8686
    87 Croaks unless a L<Config::Tiny> object is supplied as C<config>.
     87Croaks unless an L<OpenGuides::Config> object is supplied as C<config>.
    8888Acceptable values for C<cookie_expires> are C<never>, C<month>,
    8989C<year>; anything else will default to C<month>.
     
    9494    my ($class, %args) = @_;
    9595    my $config = $args{config} or croak "No config object supplied";
    96     croak "Config object not a Config::Tiny"
    97         unless UNIVERSAL::isa( $config, "Config::Tiny" );
     96    croak "Config object not an OpenGuides::Config"
     97        unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
    9898    my $cookie_name = $class->_get_cookie_name( config => $config );
    9999    my $expires;
     
    137137  );
    138138
    139 Croaks unless a L<Config::Tiny> object is supplied as C<config>.
     139Croaks unless an L<OpenGuides::Config> object is supplied as C<config>.
    140140Returns default values for any parameter not specified in cookie.
    141141
     
    145145    my ($class, %args) = @_;
    146146    my $config = $args{config} or croak "No config object supplied";
    147     croak "Config object not a Config::Tiny"
    148         unless UNIVERSAL::isa( $config, "Config::Tiny" );
     147    croak "Config object not an OpenGuides::Config"
     148        unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
    149149    my %cookies = CGI::Cookie->fetch;
    150150    my $cookie_name = $class->_get_cookie_name( config => $config );
     
    186186    my ($class, %args) = @_;
    187187    my $config = $args{config} or croak "No config object supplied";
    188     croak "Config object not a Config::Tiny"
    189         unless UNIVERSAL::isa( $config, "Config::Tiny" );
     188    croak "Config object not an OpenGuides::Config"
     189        unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
    190190    my $cookie_name = $class->_get_rc_cookie_name( config => $config );
    191191    # See explanation of expiry date hack above in make_prefs_cookie.
     
    213213  );
    214214
    215 Croaks unless a L<Config::Tiny> object is supplied as C<config>.
     215Croaks unless an L<OpenGuides::Config> object is supplied as C<config>.
    216216Returns the time (as seconds since epoch) of the user's last visit to
    217217Recent Changes.
     
    222222    my ($class, %args) = @_;
    223223    my $config = $args{config} or croak "No config object supplied";
    224     croak "Config object not a Config::Tiny"
    225         unless UNIVERSAL::isa( $config, "Config::Tiny" );
     224    croak "Config object not an OpenGuides::Config"
     225        unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
    226226    my %cookies = CGI::Cookie->fetch;
    227227    my $cookie_name = $class->_get_rc_cookie_name( config => $config );
     
    236236sub _get_cookie_name {
    237237    my ($class, %args) = @_;
    238     my $site_name = $args{config}->{_}->{site_name}
     238    my $site_name = $args{config}->site_name
    239239        or croak "No site name in config";
    240240    return $site_name . "_userprefs";
     
    243243sub _get_rc_cookie_name {
    244244    my ($class, %args) = @_;
    245     my $site_name = $args{config}->{_}->{site_name}
     245    my $site_name = $args{config}->site_name
    246246        or croak "No site name in config";
    247247    return $site_name . "_last_rc_visit";
  • trunk/lib/OpenGuides/RDF.pm

    r586 r587  
    2525
    2626  use CGI::Wiki;
    27   use Config::Tiny;
     27  use OpenGuides::Config;
    2828  use OpenGuides::RDF;
    2929
    3030  my $wiki = CGI::Wiki->new( ... );
    31   my $config = Config::Tiny->read( "wiki.conf" );
     31  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    3232  my $rdf_writer = OpenGuides::RDF->new( wiki   => $wiki,
    3333                                         config => $config );
     
    5050                                         config => $config );
    5151
    52 C<wiki> must be a L<CGI::Wiki> object and C<config> must be a
    53 L<Config::Tiny> object.  Both arguments mandatory.
     52C<wiki> must be a L<CGI::Wiki> object and C<config> must be an
     53L<OpenGuides::Config> object.  Both arguments mandatory.
    5454
    5555=cut
     
    7272
    7373    my $config = $args{config};
    74     unless ( $config && UNIVERSAL::isa( $config, "Config::Tiny" ) ) {
    75         croak "No Config::Tiny object supplied.";
     74    unless ( $config && UNIVERSAL::isa( $config, "OpenGuides::Config" ) ) {
     75        croak "No OpenGuides::Config object supplied.";
    7676    }
    7777    $self->{config} = $config;
    7878
    79     $self->{site_name} = $config->{_}->{site_name};
     79    $self->{site_name} = $config->site_name;
    8080    $self->{make_node_url} = sub {
    8181        my ($node_name, $version) = @_;
    8282        if ( defined $version ) {
    83             return $config->{_}->{script_url} . uri_escape($config->{_}->{script_name}) . "?id=" . uri_escape($wiki->formatter->node_name_to_node_param($node_name)) . ";version=" . uri_escape($version);
     83            return $config->script_url . uri_escape($config->script_name) . "?id=" . uri_escape($wiki->formatter->node_name_to_node_param($node_name)) . ";version=" . uri_escape($version);
    8484        } else {
    85             return $config->{_}->{script_url} . uri_escape($config->{_}->{script_name}) . "?id=" . uri_escape($wiki->formatter->node_name_to_node_param($node_name));
     85            return $config->script_url . uri_escape($config->script_name) . "?id=" . uri_escape($wiki->formatter->node_name_to_node_param($node_name));
    8686        }
    8787    };
    88     $self->{default_city}     = $config->{_}->{default_city}     || "";
    89     $self->{default_country}  = $config->{_}->{default_country}  || "";
    90     $self->{site_description} = $config->{_}->{site_description} || "";
     88    $self->{default_city}     = $config->default_city     || "";
     89    $self->{default_country}  = $config->default_country  || "";
     90    $self->{site_description} = $config->site_desc        || "";
    9191
    9292    return $self;
     
    269269        site_description => $self->{site_description},
    270270        make_node_url => $self->{make_node_url},
    271         recent_changes_link => $self->{config}->{_}->{script_url} . uri_escape($self->{config}->{_}->{script_name}) . "?RecentChanges"
     271        recent_changes_link => $self->{config}->script_url . uri_escape($self->{config}->script_name) . "?RecentChanges"
    272272     );
    273273
  • trunk/lib/OpenGuides/SuperSearch.pm

    r586 r587  
    2323
    2424  use CGI;
    25   use Config::Tiny;
     25  use OpenGuides::Config;
    2626  use OpenGuides::SuperSearch;
    2727
    28   my $config = Config::Tiny->read( "wiki.conf" );
     28  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    2929  my $search = OpenGuides::SuperSearch->new( config => $config );
    3030  my %vars = CGI::Vars();
     
    3737=item B<new>
    3838
    39   my $config = Config::Tiny->read( "wiki.conf" );
     39  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    4040  my $search = OpenGuides::SuperSearch->new( config => $config );
    4141
     
    5151
    5252    $self->{wiki}     = $wiki;
    53     $self->{wikimain} = $config->{_}{script_url} . $config->{_}{script_name};
    54     $self->{css}      = $config->{_}{stylesheet_url};
    55     $self->{head}     = $config->{_}{site_name} . " Search";
    56 
    57     my $geo_handler = $config->{_}{geo_handler} || 1;
     53    $self->{wikimain} = $config->script_url . $config->script_name;
     54    $self->{css}      = $config->stylesheet_url;
     55    $self->{head}     = $config->site_name . " Search";
     56
     57    my $geo_handler = $config->geo_handler;
    5858    my %locator_params;
    5959    if ( $geo_handler == 1 ) {
     
    8989  my $config = $search->config;
    9090
    91 An accessor; returns the underlying L<Config::Tiny> object.
     91An accessor; returns the underlying L<OpenGuides::Config> object.
    9292
    9393=cut
     
    154154         && defined $self->{x} && defined $self->{y} ) {
    155155        $doing_search = 1;
    156         # Make sure to pass the criteria to the template.                   
    157         $tt_vars{dist} = $self->{distance_in_metres}; 
    158         if ( $self->config->{_}{geo_handler} eq 1 ) {
    159             $tt_vars{coord_field_1_value} = $self->{os_x}; 
    160             $tt_vars{coord_field_2_value} = $self->{os_y}; 
    161         } elsif ( $self->config->{_}{geo_handler} eq 2 ) {
    162             $tt_vars{coord_field_1_value} = $self->{osie_x}; 
    163             $tt_vars{coord_field_2_value} = $self->{osie_y}; 
    164         } elsif ( $self->config->{_}{geo_handler} eq 3 ) {
    165             $tt_vars{coord_field_1_value} = $self->{latitude}; 
    166             $tt_vars{coord_field_2_value} = $self->{longitude}; 
    167         }                                               
     156        # Make sure to pass the criteria to the template.
     157        $tt_vars{dist} = $self->{distance_in_metres};
     158        if ( $self->config->geo_handler eq 1 ) {
     159            $tt_vars{coord_field_1_value} = $self->{os_x};
     160            $tt_vars{coord_field_2_value} = $self->{os_y};
     161        } elsif ( $self->config->geo_handler eq 2 ) {
     162            $tt_vars{coord_field_1_value} = $self->{osie_x};
     163            $tt_vars{coord_field_2_value} = $self->{osie_y};
     164        } elsif ( $self->config->geo_handler eq 3 ) {
     165            $tt_vars{coord_field_1_value} = $self->{latitude};
     166            $tt_vars{coord_field_2_value} = $self->{longitude};
     167        }
    168168        $self->run_distance_search;
    169169    }
     
    609609    # and supported by our method of distance calculation.
    610610    if ( defined $vars{os_x} && defined $vars{os_y} && defined $vars{os_dist}
    611          && $self->config->{_}{geo_handler} eq 1 ) {
     611         && $self->config->geo_handler eq 1 ) {
    612612        $self->{x} = $vars{os_x};
    613613        $self->{y} = $vars{os_y};
     
    615615    } elsif ( defined $vars{osie_x} && defined $vars{osie_y}
    616616         && defined $vars{osie_dist}
    617          && $self->config->{_}{geo_handler} eq 2 ) {
     617         && $self->config->geo_handler eq 2 ) {
    618618        $self->{x} = $vars{osie_x};
    619619        $self->{y} = $vars{osie_y};
     
    622622              && defined $vars{latlong_dist} ) {
    623623        # All handlers can do lat/long, but they all do it differently.
    624         if ( $self->config->{_}{geo_handler} eq 1 ) {
     624        if ( $self->config->geo_handler eq 1 ) {
    625625            require Geography::NationalGrid::GB;
    626626            my $point = Geography::NationalGrid::GB->new(
     
    630630            $self->{x} = $point->easting;
    631631            $self->{y} = $point->northing;
    632         } elsif ( $self->config->{_}{geo_handler} eq 2 ) {
     632        } elsif ( $self->config->geo_handler eq 2 ) {
    633633            require Geography::NationalGrid::IE;
    634634            my $point = Geography::NationalGrid::IE->new(
     
    638638            $self->{x} = $point->easting;
    639639            $self->{y} = $point->northing;
    640         } elsif ( $self->config->{_}{geo_handler} eq 3 ) {
     640        } elsif ( $self->config->geo_handler eq 3 ) {
    641641            require Geo::Coordinates::UTM;
    642642            my ($zone, $x, $y) = Geo::Coordinates::UTM::latlon_to_utm(
    643                                                 $self->config->{_}{ellipsoid},
     643                                                $self->config->ellipsoid,
    644644                                                $vars{latitude},
    645645                                                $vars{longitude},
  • trunk/lib/OpenGuides/Template.pm

    r586 r587  
    2727=head1 SYNOPSIS
    2828
    29   use Config::Tiny;
     29  use OpenGuides::Config;
    3030  use OpenGuides::Utils;
    3131  use OpenGuides::Template;
    3232
    33   my $config = Config::Tiny->read('wiki.conf');
     33  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    3434  my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    3535
     
    108108    croak "No template supplied" unless $args{template};
    109109    my $config = $args{config} or croak "No config supplied";
    110     my $template_path = $config->{_}->{template_path};
    111     my $custom_template_path = $config->{_}->{custom_template_path} || "";
     110    my $template_path = $config->template_path;
     111    my $custom_template_path = $config->custom_template_path || "";
    112112    my $tt = Template->new( { INCLUDE_PATH => "$custom_template_path:$template_path" } );
    113113
    114     my $script_name = $config->{_}->{script_name};
    115     my $script_url  = $config->{_}->{script_url};
    116 
    117     # Ensure that script_url ends in a '/' - this is done in Build.PL but
    118     # we need to allow for people editing the config file by hand later.
    119     $script_url .= "/" unless $script_url =~ /\/$/;
     114    my $script_name = $config->script_name;
     115    my $script_url  = $config->script_url;
    120116
    121117    # Check cookie to see if we need to set the formatting_rules_link.
    122118    my ($formatting_rules_link, $omit_help_links);
    123     my $formatting_rules_node = $config->{_}->{formatting_rules_node} ||"";
     119    my $formatting_rules_node = $config->formatting_rules_node ||"";
    124120    my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config);
    125121    if ( $cookie_data{omit_help_links} ) {
     
    133129
    134130    my $enable_page_deletion = 0;
    135     if ( $config->{_}->{enable_page_deletion}
    136          and ( lc($config->{_}->{enable_page_deletion}) eq "y"
    137                or $config->{_}->{enable_page_deletion} eq "1" )
     131    if ( $config->enable_page_deletion
     132         and ( lc($config->enable_page_deletion) eq "y"
     133               or $config->enable_page_deletion eq "1" )
    138134       ) {
    139135        $enable_page_deletion = 1;
    140136    }
    141137
    142     my $tt_vars = { site_name             => $config->{_}->{site_name},
     138    my $tt_vars = { site_name             => $config->site_name,
    143139                    cgi_url               => $script_name,
    144140                    full_cgi_url          => $script_url . $script_name,
    145                     contact_email         => $config->{_}->{contact_email},
    146                     stylesheet            => $config->{_}->{stylesheet_url},
     141                    contact_email         => $config->contact_email,
     142                    stylesheet            => $config->stylesheet_url,
    147143                    home_link             => $script_url . $script_name,
    148                     home_name             => $config->{_}->{home_name},
    149                     navbar_on_home_page   => $config->{_}->{navbar_on_home_page},
     144                    home_name             => $config->home_name,
     145                    navbar_on_home_page   => $config->navbar_on_home_page,
    150146                    omit_help_links       => $omit_help_links,
    151147                    formatting_rules_link => $formatting_rules_link,
     
    153149                    openguides_version    => $OpenGuides::VERSION,
    154150                    enable_page_deletion  => $enable_page_deletion,
    155                     language              => $config->{_}->{default_language},
     151                    language              => $config->default_language,
    156152    };
    157153
     
    237233    my $formatter = $args{wiki}->formatter;
    238234    my $config = $args{config};
    239     my $script_name = $config->{_}->{script_name};
     235    my $script_name = $config->script_name;
    240236
    241237    # Categories and locales are displayed as links in the page footer.
     
    290286        }
    291287        # Data for the distance search forms on the node display.
    292         my $geo_handler = $config->{_}{geo_handler} || 1;
     288        my $geo_handler = $config->geo_handler;
    293289        if ( $geo_handler == 1 ) {
    294290            %vars = (
     
    330326        }
    331327
    332         my $geo_handler = $config->{_}{geo_handler} || 1;
     328        my $geo_handler = $config->geo_handler;
    333329        if ( $geo_handler == 1 ) {
    334330            require Geography::NationalGrid::GB;
     
    429425            if ( $lat && $long ) {
    430426                my ($zone, $easting, $northing) =
    431                  Geo::Coordinates::UTM::latlon_to_utm( $config->{_}{ellipsoid},
     427                 Geo::Coordinates::UTM::latlon_to_utm( $config->ellipsoid,
    432428                                                       $lat, $long );
    433429                $easting  =~ s/\..*//; # chop off decimal places
  • trunk/lib/OpenGuides/Test.pm

    r586 r587  
    11package OpenGuides::Test;
    22
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44
    55use strict;
    66use vars qw( $VERSION );
    7 $VERSION = '0.01';
     7$VERSION = '0.02';
    88
    99use CGI;
     
    2626
    2727  my $config = OpenGuides::Test->make_basic_config;
    28   $config->{_}{default_language} = "nl";
     28  $config->default_language( "nl" );
    2929
    3030  my $guide = OpenGuides->new( config => $config );
     
    4545
    4646  my $config = OpenGuides::Test->make_basic_config;
    47   $config->{_}{default_language} = "nl";
     47  $config->default_language( "nl" );
    4848
    49 Makes a L<Config::Tiny> object with needed fields pre-filled.  You can
     49Makes an L<OpenGuides::Config> object with needed fields pre-filled.  You can
    5050mess with it as you like then.
    5151
     
    5353
    5454sub make_basic_config {
    55     my $config = Config::Tiny->new;
    56     $config->{_} = {
     55    my $config = OpenGuides::Config->new(
     56           vars => {
    5757                     dbtype               => "sqlite",
    5858                     dbname               => "t/node.db",
     
    6565                     home_name            => "Home",
    6666                     geo_handler          => 1,
    67                    };
     67                   }
     68    );
    6869    return $config;
    6970}
     
    7172=item B<write_data>
    7273
     74  my $config = OpenGuides::Test->make_basic_config;
    7375  my $guide = OpenGuides->new( config => $config );
    7476
  • trunk/lib/OpenGuides/Utils.pm

    r586 r587  
    2424=head1 SYNOPSIS
    2525
    26   use CGI::Wiki;
    27   use Config::Tiny;
     26  use OpenGuide::Config;
    2827  use OpenGuides::Utils;
    2928
    30   my $config = Config::Tiny->read( "wiki.conf" );
     29  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    3130  my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    3231
     
    3736=item B<make_wiki_object>
    3837
    39   my $config = Config::Tiny->read( "wiki.conf" );
     38  my $config = OpenGuides::Config->new( file => "wiki.conf" );
    4039  my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    4140
    42 Croaks unless a C<Config::Tiny> object is supplied.  Returns a
     41Croaks unless an C<OpenGuides::Config> object is supplied.  Returns a
    4342C<CGI::Wiki> object made from the given config file on success,
    4443croaks if any other error occurs.
     
    6766    my ($class, %args) = @_;
    6867    my $config = $args{config} or croak "No config param supplied";
    69     croak "config param isn't a Config::Tiny object"
    70         unless UNIVERSAL::isa( $config, "Config::Tiny" );
     68    croak "config param isn't an OpenGuides::Config object"
     69        unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
    7170
    7271    # Require in the right database module.
    73     my $dbtype = $config->{_}->{dbtype};
     72    my $dbtype = $config->dbtype;
    7473
    7574    my %cgi_wiki_exts = (
     
    8584    # Make store.
    8685    my $store = $cgi_wiki_module->new(
    87         dbname => $config->{_}{dbname},
    88         dbuser => $config->{_}{dbuser},
    89         dbpass => $config->{_}{dbpass},
    90         dbhost => $config->{_}{dbhost},
     86        dbname => $config->dbname,
     87        dbuser => $config->dbuser,
     88        dbpass => $config->dbpass,
     89        dbhost => $config->dbhost,
    9190    );
    9291
    9392    # Make search.
    9493    my $search;
    95     if ( $config->{_}{use_plucene}
    96          && ( lc($config->{_}{use_plucene}) eq "y"
    97               || $config->{_}{use_plucene} == 1 )
     94    if ( $config->use_plucene
     95         && ( lc($config->use_plucene) eq "y"
     96              || $config->use_plucene == 1 )
    9897       ) {
    9998        require CGI::Wiki::Search::Plucene;
    10099        $search = CGI::Wiki::Search::Plucene->new(
    101                                        path => $config->{_}{indexing_directory}
     100                                       path => $config->indexing_directory,
    102101                                                 );
    103102    } else {
     
    105104        require Search::InvertedIndex::DB::DB_File_SplitHash;
    106105        my $indexdb = Search::InvertedIndex::DB::DB_File_SplitHash->new(
    107             -map_name  => $config->{_}{indexing_directory},
     106            -map_name  => $config->indexing_directory,
    108107            -lock_mode => "EX"
    109108        );
     
    112111
    113112    # Make formatter.
    114     my $script_name = $config->{_}->{script_name};
    115     my $search_url = $config->{_}->{script_url} . "supersearch.cgi";
     113    my $script_name = $config->script_name;
     114    my $search_url = $config->script_url . "supersearch.cgi";
    116115
    117116    my %macros = (
  • trunk/preferences.cgi

    r586 r587  
    55
    66use CGI;
    7 use Config::Tiny;
     7use OpenGuides::Config;
    88use OpenGuides::CGI;
    99use OpenGuides::Utils;
    1010use OpenGuides::Template;
    1111
    12 my $config = Config::Tiny->read("wiki.conf");
     12my $config = OpenGuides::Config->new( file => "wiki.conf" );
    1313my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    1414my $cgi = CGI->new();
  • trunk/supersearch.cgi

    r586 r587  
    55
    66use CGI;
    7 use Config::Tiny;
     7use OpenGuides::Config;
    88use OpenGuides::SuperSearch;
    99
    10 my $config = Config::Tiny->read( "wiki.conf" );
     10my $config = OpenGuides::Config->new( file => "wiki.conf" );
    1111my $search = OpenGuides::SuperSearch->new( config => $config );
    1212my %vars = CGI::Vars();
  • trunk/t/01_load.t

    r586 r587  
    1 use Test::More tests => 6;
     1use Test::More tests => 7;
    22
    33use_ok( "OpenGuides" );
    44use_ok( "OpenGuides::CGI" );
     5use_ok( "OpenGuides::Config" );
    56use_ok( "OpenGuides::RDF" );
    67use_ok( "OpenGuides::SuperSearch" );
  • trunk/t/11_utils.t

    r586 r587  
    11use strict;
    2 use Config::Tiny;
     2use OpenGuides::Config;
    33use OpenGuides::Utils;
    44use Test::More tests => 7;
     
    88
    99eval { my $wiki = OpenGuides::Utils->make_wiki_object( config => "foo" ); };
    10 ok( $@, "...and if config param isn't a Config::Tiny object" );
     10ok( $@, "...and if config param isn't an OpenGuides::Config object" );
    1111
    1212eval { require DBD::SQLite; };
     
    1717      unless $have_sqlite;
    1818
    19     my $config = Config::Tiny->new;
    20     $config->{_} = {
     19    my $config = OpenGuides::Config->new(
     20           vars => {
    2121                     dbtype             => "sqlite",
    2222                     dbname             => "t/node.db",
     
    2424                     script_url         => "",
    2525                     script_name        => "",
    26                    };
     26                   }
     27    );
    2728
    2829    my $wiki = eval {
     
    3031    };
    3132    is( $@, "",
    32         "...but not if a Config::Tiny object with suitable data is supplied" );
     33        "...but not with an OpenGuides::Config object with suitable data" );
    3334    isa_ok( $wiki, "CGI::Wiki" );
    3435
  • trunk/t/13_cookies.t

    r586 r587  
    11use strict;
    2 use Config::Tiny;
     2use OpenGuides::Config;
    33use OpenGuides::CGI;
    44use Time::Piece;
     
    1010
    1111eval { OpenGuides::CGI->make_prefs_cookie( config => "foo" ); };
    12 ok( $@, "...or if config isn't a Config::Tiny" );
     12ok( $@, "...or if config isn't an OpenGuides::Config" );
    1313
    14 my $config = Config::Tiny->new;
    15 $config->{_} = {
    16                  site_name => "Test Site",
    17                };
     14my $config = OpenGuides::Config->new( vars => { site_name => "Test Site" } );
    1815
    1916eval { OpenGuides::CGI->make_prefs_cookie( config => $config ); };
     
    5148
    5249eval { OpenGuides::CGI->get_prefs_from_cookie( config => "foo" ); };
    53 ok( $@, "...or if config isn't a Config::Tiny" );
     50ok( $@, "...or if config isn't an OpenGuides::Config" );
    5451
    5552eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); };
  • trunk/t/14_recent_changes_cookies.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides;
    55use OpenGuides::CGI;
     
    1212
    1313eval { OpenGuides::CGI->make_recent_changes_cookie( config => "foo" ); };
    14 ok( $@, "...or if config isn't a Config::Tiny" );
     14ok( $@, "...or if config isn't an OpenGuides::Config" );
    1515
    16 my $config = Config::Tiny->new;
    17 $config->{_} = {
    18                  site_name => "Test Site",
    19                };
     16my $config = OpenGuides::Config->new( vars => { site_name => "Test Site" } );
    2017
    2118eval { OpenGuides::CGI->make_recent_changes_cookie( config => $config ); };
     
    4340
    4441eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => "foo" ); };
    45 ok( $@, "...or if config isn't a Config::Tiny" );
     42ok( $@, "...or if config isn't an OpenGuides::Config" );
    4643
    4744eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); };
     
    6259
    6360    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    64     my $config = Config::Tiny->new;
    65     $config->{_} = {
     61    my $config = OpenGuides::Config->new(
     62           vars => {
    6663                     dbtype             => "sqlite",
    6764                     dbname             => "t/node.db",
     
    7269                     template_path      => "./templates",
    7370                     home_name          => "Home",
    74                    };
     71                   }
     72    );
    7573    my $guide = OpenGuides->new( config => $config );
    7674
  • trunk/t/15_template.t

    r586 r587  
    11use strict;
    2 use Config::Tiny;
    32use Cwd;
    43use CGI::Cookie;
    54use CGI::Wiki::Formatter::UseMod;
     5use OpenGuides::Config;
    66use OpenGuides::Template;
    77use Test::MockObject;
    88use Test::More tests => 27;
    99
    10 my $config = Config::Tiny->new;
    11 $config->{_} = {
     10my $config = OpenGuides::Config->new(
     11       vars => {
    1212                 template_path         => cwd . '/t/templates',
    1313                 site_name             => 'CGI::Wiki Test Site',
     
    2020                 home_name             => 'Home Page',
    2121                 formatting_rules_node => 'Rules',
    22                };
     22               }
     23);
    2324
    2425# White box testing - we know that OpenGuides::Template only actually uses
     
    112113
    113114# Test that home_link is set correctly when script_name is blank.
    114 $config->{_} = {
     115$config = OpenGuides::Config->new(
     116       vars => {
    115117                 template_path         => cwd . '/t/templates',
    116118                 site_name             => 'CGI::Wiki Test Site',
    117119                 script_url            => 'http://wiki.example.com/',
    118120                 script_name           => '',
    119                };
     121               }
     122);
    120123$output = OpenGuides::Template->output(
    121124    wiki     => $fake_wiki,
     
    128131# Test that full_cgi_url comes out right if the trailing '/' is
    129132# missing from script_url in the config file.
    130 $config->{_} = {
     133$config = OpenGuides::Config->new(
     134       vars => {
    131135                 template_path         => cwd . '/t/templates',
    132136                 site_name             => 'CGI::Wiki Test Site',
    133137                 script_url            => 'http://wiki.example.com',
    134138                 script_name           => 'wiki.cgi',
    135                };
     139               }
     140);
    136141$output = OpenGuides::Template->output(
    137142    wiki     => $fake_wiki,
     
    167172
    168173# Test that enable_page_deletion is set correctly in various circumstances.
    169 $config = Config::Tiny->new;
    170 $config->{_}->{template_path} = cwd . "/t/templates";
    171 $config->{_}->{site_name} = "Test Site";
    172 $config->{_}->{script_url} = "/";
    173 $config->{_}->{script_name} = "";
     174$config = OpenGuides::Config->new(
     175    vars => {
     176              template_path => cwd . "/t/templates",
     177              site_name     => "Test Site",
     178              script_url    => "/",
     179              script_name   => "",
     180            },
     181);
    174182
    175183$output = OpenGuides::Template->output(
     
    181189      "enable_page_deletion var set correctly when not specified in conf" );
    182190
    183 $config->{_}->{enable_page_deletion} = "n";
     191$config->enable_page_deletion( "n" );
    184192$output = OpenGuides::Template->output(
    185193    wiki     => $fake_wiki,
     
    190198      "enable_page_deletion var set correctly when set to 'n' in conf" );
    191199
    192 $config->{_}->{enable_page_deletion} = "y";
     200$config->enable_page_deletion( "y" );
    193201$output = OpenGuides::Template->output(
    194202    wiki     => $fake_wiki,
     
    199207      "enable_page_deletion var set correctly when set to 'y' in conf" );
    200208
    201 $config->{_}->{enable_page_deletion} = 0;
     209$config->enable_page_deletion( 0 );
    202210$output = OpenGuides::Template->output(
    203211    wiki     => $fake_wiki,
     
    208216      "enable_page_deletion var set correctly when set to '0' in conf" );
    209217
    210 $config->{_}->{enable_page_deletion} = 1;
     218$config->enable_page_deletion( 1 );
    211219$output = OpenGuides::Template->output(
    212220    wiki     => $fake_wiki,
  • trunk/t/16_test_tester.t

    r586 r587  
    2323CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    2424my $config = OpenGuides::Test->make_basic_config;
    25 $config->{_}{site_name} = "Test Site";
     25$config->site_name( "Test Site" );
    2626my $guide = OpenGuides->new( config => $config );
    2727
  • trunk/t/21_rdf.t

    r586 r587  
    11use CGI::Wiki::Setup::SQLite;
    2 use Config::Tiny;
     2use OpenGuides::Config;
    33use OpenGuides::RDF;
    44use OpenGuides::Utils;
     
    1414
    1515    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    16     my $config = Config::Tiny->new;
    17     $config->{_} = {
     16    my $config = OpenGuides::Config->new(
     17           vars => {
    1818                     dbtype             => "sqlite",
    1919                     dbname             => "t/node.db",
     
    2424                     default_city       => "London",
    2525                     default_country    => "United Kingdom",
    26                    };
     26                   }
     27    );
    2728
    2829    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
  • trunk/t/22_rss_modwiki.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides;
    55use OpenGuides::RDF;
     
    2626
    2727CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    28 my $config = Config::Tiny->new;
    29 $config->{_} = {
     28my $config = OpenGuides::Config->new(
     29       vars => {
    3030                 dbtype             => "sqlite",
    3131                 dbname             => "t/node.db",
     
    3737                 home_name          => "Home",
    3838                 use_plucene        => 1
    39                };
     39               }
     40);
    4041
    4142# Basic sanity check first.
  • trunk/t/25_write_geo_data.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides;
    55use OpenGuides::Test;
     
    3737
    3838CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    39 my $config = Config::Tiny->new;
    40 $config->{_} = {
     39my $config = OpenGuides::Config->new(
     40       vars => {
    4141                 dbtype             => "sqlite",
    4242                 dbname             => "t/node.db",
     
    4848                 use_plucene        => 1,
    4949                 geo_handler        => 1,
    50                };
     50               }
     51);
    5152
    5253# First check that British National Grid will accept both OS X/Y and lat/long,
     
    102103
    103104# Now check Irish National Grid.
    104 $config->{_}{geo_handler} = 2;
     105$config->geo_handler( 2 );
    105106$guide = OpenGuides->new( config => $config );
    106107is( $guide->locator->x_field, "osie_x", "correct x field" );
     
    151152
    152153# Finally check UTM.
    153 $config->{_}{geo_handler} = 3;
    154 $config->{_}{ellipsoid} = "Airy";
     154$config->geo_handler( 3 );
     155$config->ellipsoid( "Airy" );
    155156$guide = OpenGuides->new( config => $config );
    156157is( $guide->locator->x_field, "easting", "correct x field" );
  • trunk/t/26_geo_data_search_form.t

    r586 r587  
    4343CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    4444my $config = OpenGuides::Test->make_basic_config;
    45 $config->{_}{use_plucene} = 1;
     45$config->use_plucene( 1 );
    4646
    4747# British National Grid guides should have os_x/os_y/os_dist search fields.
     
    7979
    8080# Irish National Grid guides should have osie_x/osie_y/osie_dist.
    81 $config->{_}{geo_handler} = 2;
     81$config->geo_handler( 2 );
    8282$guide = OpenGuides->new( config => $config );
    8383
     
    110110
    111111# UTM guides should have latitude/longitude/latlong_dist.
    112 $config->{_}{geo_handler} = 3;
    113 $config->{_}{ellipsoid} = "Airy";
     112$config->geo_handler( 3 );
     113$config->ellipsoid( "Airy" );
    114114$guide = OpenGuides->new( config => $config );
    115115
  • trunk/t/27_geo_data_edit_form.t

    r586 r587  
    4444CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    4545my $config = OpenGuides::Test->make_basic_config;
    46 $config->{_}{use_plucene} = 1;
     46$config->use_plucene( 1 );
    4747
    4848# British National Grid guides should have os_x/os_y fields.
     
    8989
    9090# Irish National Grid guides should have osie_x/osie_y fields.
    91 $config->{_}{geo_handler} = 2;
     91$config->geo_handler( 2 );
    9292$guide = OpenGuides->new( config => $config );
    9393$wiki = $guide->wiki;
     
    129129
    130130# UTM guides should have lat/long fields.
    131 $config->{_}{geo_handler} = 3;
    132 $config->{_}{ellipsoid} = "Airy";
     131$config->geo_handler( 3 );
     132$config->ellipsoid( "Airy" );
    133133$guide = OpenGuides->new( config => $config );
    134134$wiki = $guide->wiki;
  • trunk/t/31_supersearch.t

    r586 r587  
    1717    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    1818    my $config = OpenGuides::Test->make_basic_config;
    19     $config->{_}{script_name} = "wiki.cgi";
    20     $config->{_}{script_url} = "http://example.com/";
     19    $config->script_name( "wiki.cgi" );
     20    $config->script_url( "http://example.com/" );
    2121
    2222    # Plucene is the recommended searcher now.
    2323    eval { require CGI::Wiki::Search::Plucene; };
    2424    unless ( $@ ) {
    25         $config->{_}{use_plucene} = 1;
     25        $config->use_plucene( 1 );
    2626    }
    2727
  • trunk/t/32_supersearch_simple_metadata.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides::SuperSearch;
    55use Test::More tests => 10;
     
    1717
    1818    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    19     my $config = Config::Tiny->new;
    20     $config->{_} = {
     19    my $config = OpenGuides::Config->new(
     20           vars => {
    2121                     dbtype             => "sqlite",
    2222                     dbname             => "t/node.db",
     
    2626                     site_name          => "Test Site",
    2727                     template_path      => "./templates",
    28                    };
     28                   }
     29    );
    2930
    3031    # Plucene is the recommended searcher now.
    3132    eval { require CGI::Wiki::Search::Plucene; };
    3233    unless ( $@ ) {
    33         $config->{_}{use_plucene} = 1;
     34        $config->use_plucene( 1 );
    3435    }
    3536
  • trunk/t/33_supersearch_advanced_search.t

    r586 r587  
    22use CGI::Wiki::Plugin::Locator::Grid; # use directly to help debug
    33use CGI::Wiki::Setup::SQLite;
    4 use Config::Tiny;
     4use OpenGuides::Config;
    55use OpenGuides::SuperSearch;
    66use OpenGuides::Test;
     
    2929CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    3030
    31 my $config = Config::Tiny->new;
    32 $config->{_} = {
     31my $config = OpenGuides::Config->new(
     32       vars => {
    3333                 dbtype             => "sqlite",
    3434                 dbname             => "t/node.db",
     
    4040                 use_plucene        => 1,
    4141                 geo_handler        => 1,
    42            };
     42           }
     43);
    4344my $search = OpenGuides::SuperSearch->new( config => $config );
    4445my $guide = OpenGuides->new( config => $config );
  • trunk/t/33_supersearch_advanced_search_utm.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides::SuperSearch;
    55use OpenGuides::Test;
     
    2828CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    2929
    30 my $config = Config::Tiny->new;
    31 $config->{_} = {
     30my $config = OpenGuides::Config->new(
     31       vars => {
    3232                 dbtype             => "sqlite",
    3333                 dbname             => "t/node.db",
     
    4040                 geo_handler        => 3,
    4141                 ellipsoid          => "Airy",
    42            };
     42           }
     43);
    4344my $search = OpenGuides::SuperSearch->new( config => $config );
    4445my $guide = OpenGuides->new( config => $config );
  • trunk/t/34_supersearch_paging.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides::SuperSearch;
    55use OpenGuides::Test;
     
    2424
    2525my $config = OpenGuides::Test->make_basic_config;
    26 $config->{_}{use_plucene} = 1;
     26$config->use_plucene( 1 );
    2727my $search = OpenGuides::SuperSearch->new( config => $config );
    2828my $guide = OpenGuides->new( config => $config );
     
    3232SKIP: {
    3333    skip "Geography::NationalGrid::GB not installed", 1 if $@;
    34     $config->{_}{geo_handler} = 1;
     34    $config->geo_handler( 1 );
    3535
    3636    foreach my $i ( 1 .. 30 ) {
     
    6767    # We must create a new search object after changing the geo_handler
    6868    # in order to force it to create a fresh locator.
    69     $config->{_}{geo_handler} = 2;
     69    $config->geo_handler( 2 );
    7070    my $search = OpenGuides::SuperSearch->new( config => $config );
    7171
     
    102102    # We must create a new search object after changing the geo_handler
    103103    # in order to force it to create a fresh locator.
    104     $config->{_}{geo_handler} = 3;
    105     $config->{_}{ellipsoid} = "International";
     104    $config->geo_handler( 3 );
    106105    my $search = OpenGuides::SuperSearch->new( config => $config );
    107106
  • trunk/t/35_supersearch_two_searches.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides::SuperSearch;
    55use Test::More;
     
    3131
    3232CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    33 my $config = Config::Tiny->new;
    34 $config->{_} = {
     33my $config = OpenGuides::Config->new(
     34       vars => {
    3535                 dbtype             => "sqlite",
    3636                 dbname             => "t/node.db",
     
    4141                 template_path      => "./templates",
    4242                 geo_handler        => 1,
    43                };
     43               }
     44);
    4445
    4546# Plucene is the recommended searcher now.
    4647eval { require CGI::Wiki::Search::Plucene; };
    4748unless ( $@ ) {
    48     $config->{_}{use_plucene} = 1;
     49    $config->use_plucene( 1 );
    4950}
    5051
     
    101102
    102103# Now with Irish National Grid.
    103 $config->{_}{geo_handler} = 2;
     104$config->geo_handler( 2 );
    104105$search = OpenGuides::SuperSearch->new( config => $config );
    105106$search->run(
     
    115116
    116117# Now with UTM.
    117 $config->{_}{geo_handler} = 3;
    118 $config->{_}{ellipsoid} = "Airy";
     118$config->geo_handler( 3 );
     119$config->ellipsoid( "Airy" );
    119120$search = OpenGuides::SuperSearch->new( config => $config );
    120121$search->run(
  • trunk/t/36_supersearch_order.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides::SuperSearch;
    55use Test::More;
     
    2424
    2525CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    26 my $config = Config::Tiny->new;
    27 $config->{_} = {
     26my $config = OpenGuides::Config->new(
     27       vars => {
    2828                 dbtype             => "sqlite",
    2929                 dbname             => "t/node.db",
     
    3434                 template_path      => "./templates",
    3535                 use_plucene        => 1
    36                };
     36               }
     37);
    3738
    3839my $search = OpenGuides::SuperSearch->new( config => $config );
  • trunk/t/37_supersearch_summaries.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides::SuperSearch;
    55use Test::More;
     
    1616
    1717    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    18     my $config = Config::Tiny->new;
    19     $config->{_} = {
     18    my $config = OpenGuides::Config->new(
     19           vars => {
    2020                     dbtype             => "sqlite",
    2121                     dbname             => "t/node.db",
     
    2525                     site_name          => "Test Site",
    2626                     template_path      => "./templates",
    27                    };
     27                   }
     28    );
    2829
    2930    # Plucene is the recommended searcher now.
    3031    eval { require CGI::Wiki::Search::Plucene; };
    3132    unless ( $@ ) {
    32         $config->{_}{use_plucene} = 1;
     33        $config->use_plucene( 1 );
    3334    }
    3435
  • trunk/t/38_supersearch_params.t

    r586 r587  
    22use CGI;
    33use CGI::Wiki::Setup::SQLite;
    4 use Config::Tiny;
     4use OpenGuides::Config;
    55use OpenGuides::SuperSearch;
    66use Test::More;
     
    3838
    3939CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    40 my $config = Config::Tiny->new;
    41 $config->{_} = {
     40my $config = OpenGuides::Config->new(
     41       vars => {
    4242                 dbtype             => "sqlite",
    4343                 dbname             => "t/node.db",
     
    4949                 use_plucene        => 1,
    5050                 geo_handler        => 1, # British National Grid
    51                };
     51               }
     52);
    5253
    5354# Check the British National Grid case.
     
    9495
    9596# Check the Irish National Grid case.
    96 $config->{_}{geo_handler} = 2; # Irish National Grid
     97$config->geo_handler( 2 );
    9798
    9899$q = CGI->new( "" );
     
    138139
    139140# Check the UTM case.
    140 $config->{_}{geo_handler} = 3; # UTM
    141 $config->{_}{ellipsoid} = "Airy";
     141$config->geo_handler( 3 );
     142$config->ellipsoid( "Airy" );
    142143
    143144$q = CGI->new( "" );
  • trunk/t/39_supersearch_form.t

    r586 r587  
    4343CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    4444my $config = OpenGuides::Test->make_basic_config;
    45 $config->{_}{use_plucene} = 1;
     45$config->use_plucene( 1 );
    4646
    4747# British National Grid guides should have os and latlong search fields.
     
    7171
    7272# Irish National Grid guides should have osie and latlong.
    73 $config->{_}{geo_handler} = 2;
     73$config->geo_handler( 2 );
    7474$search = OpenGuides::SuperSearch->new( config => $config );
    7575$output = $search->run( return_output => 1 );
     
    9696
    9797# UTM guides should have latitude/longitude/latlong_dist only.
    98 $config->{_}{geo_handler} = 3;
    99 $config->{_}{ellipsoid} = "Airy";
     98$config->geo_handler( 3 );
     99$config->ellipsoid( "Airy" );
    100100$search = OpenGuides::SuperSearch->new( config => $config );
    101101$output = $search->run( return_output => 1 );
  • trunk/t/41_deletion.t

    r586 r587  
    77
    88my $config = OpenGuides::Test->make_basic_config;
    9 $config->{_}->{site_name} = "Test Site";
    10 $config->{_}->{script_url} = "/";
     9$config->site_name( "Test Site" );
     10$config->script_url( "/" );
    1111
    1212# White box testing - we know that OpenGuides::Template only actually uses
     
    2525unlike( $output, qr/action=delete/,
    2626        "doesn't offer page deletion link by default" );
    27 $config->{_}->{enable_page_deletion} = "y";
     27$config->enable_page_deletion( "y" );
    2828$output = OpenGuides::Template->output(
    2929    wiki     => $fake_wiki,
     
    3333like( $output, qr/action=delete/,
    3434      "...but does when enable_page_deletion is set to 'y'" );
    35 $config->{_}->{enable_page_deletion} = "1";
     35$config->enable_page_deletion( 1 );
    3636$output = OpenGuides::Template->output(
    3737    wiki     => $fake_wiki,
  • trunk/t/51_display_node.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides;
    55use Test::More tests => 5;
     
    1313
    1414    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    15     my $config = Config::Tiny->new;
    16     $config->{_} = {
     15    my $config = OpenGuides::Config->new(
     16           vars => {
    1717                     dbtype             => "sqlite",
    1818                     dbname             => "t/node.db",
     
    2323                     template_path      => "./templates",
    2424                     home_name          => "Home",
    25                    };
     25                   }
     26    );
    2627    my $guide = OpenGuides->new( config => $config );
    2728    isa_ok( $guide, "OpenGuides" );
     
    3435    is( $@, "", "->display_node doesn't die" );
    3536
    36     $config->{_}->{home_name} = "My Home Page";
     37    $config->home_name( "My Home Page" );
    3738    $output = $guide->display_node( return_output => 1 );
    3839    like( $output, qr/My Home Page/, "...and defaults to the home node, and takes notice of what we want to call it" );
  • trunk/t/53_show_index.t

    r586 r587  
    1414    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    1515    my $config = OpenGuides::Test->make_basic_config;
    16     $config->{_}{script_name} = "wiki.cgi";
    17     $config->{_}{script_url} = "http://example.com/";
     16    $config->script_name( "wiki.cgi" );
     17    $config->script_url( "http://example.com/" );
    1818    my $guide = OpenGuides->new( config => $config );
    1919    isa_ok( $guide, "OpenGuides" );
  • trunk/t/54_redirect.t

    r586 r587  
    11use strict;
    22use CGI::Wiki::Setup::SQLite;
    3 use Config::Tiny;
     3use OpenGuides::Config;
    44use OpenGuides;
    55use Test::More tests => 2;
     
    1313
    1414    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    15     my $config = Config::Tiny->new;
    16     $config->{_} = {
     15    my $config = OpenGuides::Config->new(
     16           vars => {
    1717                     dbtype             => "sqlite",
    1818                     dbname             => "t/node.db",
     
    2222                     site_name          => "Test Site",
    2323                     template_path      => "./templates",
    24                    };
     24                   }
     25    );
    2526    my $guide = OpenGuides->new( config => $config );
    2627    my $wiki = $guide->wiki;
  • trunk/t/55_node_history.t

    r586 r587  
    1414    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    1515    my $config = OpenGuides::Test->make_basic_config;
    16     $config->{_}{script_name} = "mywiki.cgi";
    17     $config->{_}{script_url} = "http://example.com/";
     16    $config->script_name( "mywiki.cgi" );
     17    $config->script_url( "http://example.com/" );
    1818    my $guide = OpenGuides->new( config => $config );
    1919
  • trunk/t/62_bug_os_coords.t

    r586 r587  
    11use CGI::Wiki::Setup::SQLite;
    2 use Config::Tiny;
     2use OpenGuides::Config;
    33use Cwd;
    44use OpenGuides::Template;
     
    1414
    1515    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    16     my $config = Config::Tiny->new;
    17     $config->{_} = {
     16    my $config = OpenGuides::Config->new(
     17           vars => {
    1818                     dbtype             => "sqlite",
    1919                     dbname             => "t/node.db",
     
    2424                     template_path      => cwd . "/templates",
    2525                     geo_handler        => 1,
    26                    };
     26                   }
     27    );
    2728
    2829    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
  • trunk/t/64_bug_node_history.t

    r586 r587  
    11use CGI::Wiki::Setup::SQLite;
    2 use Config::Tiny;
     2use OpenGuides::Config;
    33use Cwd;
    44use OpenGuides;
     
    1414    CGI::Wiki::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    1515    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    16     my $config = Config::Tiny->new;
    17     $config->{_} = {
     16    my $config = OpenGuides::Config->new(
     17           vars => {
    1818                     dbtype             => "sqlite",
    1919                     dbname             => "t/node.db",
     
    2323                     site_name          => "CGI::Wiki Test Site",
    2424                     template_path      => cwd . "/templates",
    25                    };
     25                   }
     26    );
    2627
    2728    my $guide = OpenGuides->new( config => $config );
  • trunk/t/65_bug_metadata_escape.t

    r586 r587  
    11use CGI::Wiki::Setup::SQLite;
    2 use Config::Tiny;
     2use OpenGuides::Config;
    33use Cwd;
    44use OpenGuides;
     
    1313    CGI::Wiki::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    1414    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    15     my $config = Config::Tiny->new;
    16     $config->{_} = {
     15    my $config = OpenGuides::Config->new(
     16           vars => {
    1717                     dbtype             => "sqlite",
    1818                     dbname             => "t/node.db",
     
    2222                     site_name          => "CGI::Wiki Test Site",
    2323                     template_path      => cwd . "/templates",
    24                    };
     24                   }
     25    );
    2526
    2627    my $guide = OpenGuides->new( config => $config );
  • trunk/t/66_bug_latlong_representation.t

    r586 r587  
    22use CGI;
    33use CGI::Wiki::Setup::SQLite;
    4 use Config::Tiny;
     4use OpenGuides::Config;
    55use OpenGuides::CGI;
    66use OpenGuides;
     
    2525
    2626CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    27 my $config = Config::Tiny->new;
    28 $config->{_} = {
     27my $config = OpenGuides::Config->new(
     28       vars => {
    2929                 dbtype             => "sqlite",
    3030                 dbname             => "t/node.db",
     
    3737                 geo_handler        => 3, # Test w/ UTM - nat grids use X/Y
    3838                 ellipsoid          => "Airy",
    39                };
     39               }
     40);
    4041
    4142# Plucene is the recommended searcher now.
    4243eval { require CGI::Wiki::Search::Plucene; };
    4344unless ( $@ ) {
    44     $config->{_}{use_plucene} = 1;
     45    $config->use_plucene( 1 );
    4546}
    4647
  • trunk/wiki.cgi

    r586 r587  
    1010use CGI::Carp qw(croak);
    1111use CGI::Wiki;
    12 use Config::Tiny;
    1312use Geography::NationalGrid;
    1413use Geography::NationalGrid::GB;
    1514use OpenGuides;
    1615use OpenGuides::CGI;
     16use OpenGuides::Config;
    1717use OpenGuides::RDF;
    1818use OpenGuides::Utils;
     
    2121use URI::Escape;
    2222
    23 # config vars
    24 my $config = Config::Tiny->read('wiki.conf');
    25 
    26 # Read in configuration values from config file.
    27 my $script_name = $config->{_}->{script_name};
    28 my $script_url  = $config->{_}->{script_url};
    29 
    30 # Ensure that script_url ends in a '/' - this is done in Build.PL but
    31 # we need to allow for people editing the config file by hand later.
    32 $script_url .= "/" unless $script_url =~ /\/$/;
     23my $config = OpenGuides::Config->new( file => "wiki.conf" );
     24
     25my $script_name = $config->script_name;
     26my $script_url  = $config->script_url;
    3327
    3428my ($guide, $wiki, $formatter, $q);
     
    8781                                    );
    8882    } elsif ( $action eq 'delete'
    89               and ( lc($config->{_}->{enable_page_deletion}) eq "y"
    90                     or $config->{_}->{enable_page_deletion} eq "1" )
     83              and ( lc($config->enable_page_deletion) eq "y"
     84                    or $config->enable_page_deletion eq "1" )
    9185            ) {
    9286        $guide->delete_node(
     
    137131    warn $error;
    138132    print $q->header;
    139     my $contact_email = $config->{_}->{contact_email};
     133    my $contact_email = $config->contact_email;
    140134    print qq(<html><head><title>ERROR</title></head><body>
    141135             <p>Sorry!  Something went wrong.  Please contact the
Note: See TracChangeset for help on using the changeset viewer.