fixed error message and validation
[sgn.git] / lib / SGN / Context.pm
blob80b92b96d7824a3759f82d3e93c26b4a915336c1
1 =head1 NAME
3 SGN::Context - deprecated, do not use in new code
5 =cut
7 # =head1 NAME
9 # SGN::Context - configuration and context object, meant to export a
10 # similar interface to the Catalyst context object, to help smooth our
11 # transition to Catalyst.
13 # =head1 SYNOPSIS
15 # my $c = SGN::Context->new;
16 # my $c = SGN::Context->instance; # new() and instance() do the same thing
18 # # Catalyst-compatible
19 # print "my_conf_variable is ".$c->get_conf('my_conf_variable');
21 # =head1 DESCRIPTION
23 # Note that this object is a singleton, based on L<MooseX::Singleton>.
24 # There is only ever 1 instance of it.
26 # =head1 ROLES
28 # Does: L<SGN::SiteFeatures>, L<SGN::Site>
30 # =head1 OBJECT METHODS
32 # =cut
34 package SGN::Context;
35 use 5.10.0;
36 use Moose;
37 use namespace::autoclean;
39 use warnings FATAL => 'all';
41 use Carp;
42 use File::Spec;
44 use Config::JFDI;
46 use Catalyst::Utils ();
47 use CatalystX::GlobalContext '$c';
49 sub instance { shift->new(@_) }
51 # only use this object if $c is not available
52 around qw( new ) => sub {
53 return $c if $c;
55 my $orig = shift;
56 my $class = shift;
57 return $class->$orig(@_);
60 sub setup_finalize {} #< stubbed out to satisfy roles
62 sub path_to {
63 my ( $self, @relpath ) = @_;
65 @relpath = map "$_", @relpath; #< stringify whatever was passed
67 my $basepath = $self->get_conf('basepath')
68 or die "no base path conf variable defined";
69 -d $basepath or die "base path '$basepath' does not exist!";
71 return File::Spec->catfile( $basepath, @relpath );
74 sub config {
75 my $class = shift;
76 $class = ref $class if ref $class;
77 state %config;
78 return $config{$class} ||= $class->_build_config;
80 sub _build_config {
81 my ($self) = @_;
83 my $home = Catalyst::Utils::home( __PACKAGE__ );
85 return
86 Config::JFDI->open(
87 name => 'sgn',
88 path => $home,
89 substitute => {
90 UID => sub { $> },
91 USERNAME => sub { (getpwuid($>))[0] },
92 GID => sub { $) },
93 GROUPNAME => sub { (getgrgid($)))[0] },
95 default => {
96 name => 'SGN',
97 home => $home,
98 basepath => $home,
101 || die "failed to load sgn config files in dir '$home'";
104 with qw(
105 SGN::Role::Site::Config
106 SGN::Role::Site::DBConnector
107 SGN::Role::Site::DBIC
108 SGN::Role::Site::Files
109 SGN::Role::Site::Mason
110 SGN::Role::Site::SiteFeatures
113 __PACKAGE__->meta->make_immutable( inline_constructor => 0 );
116 1;#do not remove