Permalink
Browse files

moved HOME setting logic to Angelos::Home

  • Loading branch information...
1 parent 128b6e4 commit ad1f7e9762483f33de5625a3f4e2a0717f0d45d1 @dann committed Jan 14, 2009
@@ -0,0 +1,18 @@
+--- !ditz.rubyforge.org,2008-03-06/issue
+title: refactored home settings
+desc: Set home should be Angelos::Home's role. CLI, modperl, script, normal application refer it the same way
+type: :task
+component: angelos
+release:
+reporter: dann <techmemo@gmail.com>
+status: :unstarted
+disposition:
+creation_time: 2009-01-13 18:18:18.929515 Z
+references: []
+
+id: 12bbab2be2199e0511b03c53918a0a59da2ddd6b
+log_events:
+- - 2009-01-13 18:18:20.778135 Z
+ - dann <techmemo@gmail.com>
+ - created
+ - ""
View
@@ -105,9 +105,10 @@ sub setup_debug_plugins {
sub setup_home {
my $self = shift;
- my $home = Angelos::Home->guess_home( ref $self );
- Angelos::Home->set_home($home) if -d $home;
- $home;
+ my $home = Angelos::Home->home(ref $self);
+# my $home = Angelos::Home->guess_home( ref $self );
+# Angelos::Home->set_home($home) if -d $home;
+ return $home;
}
sub setup_engine {
View
@@ -3,7 +3,7 @@ use base qw(App::Cmd);
use Angelos::Home;
use Cwd;
-Angelos::Home->set_home(getcwd);
+#Angelos::Home->set_home(getcwd);
=head1 NAME
@@ -1,4 +1,6 @@
package Angelos::Config;
+use strict;
+use warnings;
use Angelos::Home;
use Angelos::Config::Loader;
use Angelos::Config::Schema;
@@ -6,8 +6,6 @@ no Mouse;
sub create_engine {
my ( $class, $r, $context_key ) = @_;
- $class->_setup_home;
-
my $app_class = $class->_load_app_class;
my $app = $app_class->new( server => 'ModPerl' );
$app->setup;
@@ -20,10 +18,6 @@ sub _load_app_class {
$app_class;
}
-sub _setup_home {
- $ENV{ANGELOS_HOME} = $ENV{DOCUMENT_ROOT};
-}
-
__PACKAGE__->meta->make_immutable;
1;
View
@@ -1,38 +1,51 @@
package Angelos::Home;
+use strict;
+use warnings;
use Angelos::Utils;
use Path::Class qw(dir file);
+use Cwd ();
our $HOME;
sub home {
- my ( $class, $appclass ) = @_;
+ my ( $class, $app_class ) = @_;
if ($HOME) {
return $HOME;
}
- $HOME = $class->guess_home($appclass);
+ $HOME ||= $class->_get_home_from_angelos_env;
+ $HOME ||= $class->_get_home_from_application_env($app_class);
+ $HOME ||= $class->_document_root;
+ $HOME ||= $class->_search_home_from_module_file_path($app_class);
+ $HOME ||= $class->_current_dir;
$HOME;
}
sub set_home {
- my ($class, $home) = @_;
+ my ( $class, $home ) = @_;
$HOME = $home;
}
-sub guess_home {
- my ( $class, $clazz ) = @_;
- return $HOME if $HOME;
-
- my $home;
+sub _get_home_from_angelos_env {
if ( $ENV{ANGELOS_HOME} ) {
- $home = dir( $ENV{ANGELOS_HOME} )->absolute->cleanup;
+ my $home = dir( $ENV{ANGELOS_HOME} )->absolute->cleanup;
return $home if -d $home;
}
- if ( my $env = Angelos::Utils::env_value( $clazz, 'HOME' ) ) {
- $home = dir($env)->absolute->cleanup;
+ return;
+}
+
+sub _get_home_from_application_env {
+ my ($class, $app_class) = @_;
+ if ( my $env = Angelos::Utils::env_value( $app_class, 'HOME' ) ) {
+ my $home = dir($env)->absolute->cleanup;
return $home if -d $home;
}
+ return;
+}
- ( my $file = "$clazz.pm" ) =~ s{::}{/}g;
+sub _search_home_from_module_file_path {
+ my ( $class, $app_class ) = @_;
+ my $home;
+ ( my $file = "$app_class.pm" ) =~ s{::}{/}g;
if ( my $inc_entry = $INC{$file} ) {
{
@@ -61,6 +74,7 @@ sub guess_home {
}
{
+
# look for an installed Angelos app
# trim the .pm off the thing ( Foo/Bar.pm -> Foo/Bar/ )
@@ -73,7 +87,19 @@ sub guess_home {
}
# we found nothing
- return 0;
+ return;
+}
+
+sub _current_dir {
+ Cwd::getcwd;
+}
+
+sub _document_root {
+ if ( $ENV{DOCUMENT_ROOT} && $ENV{MOD_PERL} ) {
+ my $home = dir( $ENV{DOCUMENT_ROOT} )->absolute->cleanup;
+ return $home if -d $home;
+ }
+ return;
}
sub path_to {
@@ -88,26 +114,3 @@ sub path_to {
}
1;
-
-__END__
-
-=head1 NAME
-
-
-=head1 SYNOPSIS
-
-=head1 DESCRIPTION
-
-
-=head1 AUTHOR
-
-Takatoshi Kitano E<lt>kitano.tk@gmail.comE<gt>
-
-=head1 SEE ALSO
-
-=head1 LICENSE
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
@@ -1,4 +1,6 @@
package Angelos::Logger;
+use strict;
+use warnings;
use Log::Dispatch::Config;
use Log::Dispatch::Configurator::YAML;
use Angelos::Config;
@@ -3,7 +3,7 @@ use base qw(App::Cmd);
use Angelos::Home;
use Cwd;
-Angelos::Home->set_home(getcwd);
+#Angelos::Home->set_home(getcwd);
1;
@@ -90,8 +90,6 @@ sub show_manual {
my ( $self, $topic, $lang ) = @_;
if ( my $file = $self->_find_topic( $topic, $lang ) ) {
my $fh = $file->openr;
-
- #open my $fh, '<:utf8', $file or die $!;
my $parser = Pod::Simple::Text->new;
my $buf;
$parser->output_string( \$buf );

0 comments on commit ad1f7e9

Please sign in to comment.