[Bps-public-commit] r12422 - in Prophet/branches/moose: .
sartak at bestpractical.com
sartak at bestpractical.com
Sat May 17 02:59:29 EDT 2008
Author: sartak
Date: Sat May 17 02:59:29 2008
New Revision: 12422
Modified:
Prophet/branches/moose/ (props changed)
Prophet/branches/moose/Makefile.PL
Prophet/branches/moose/lib/Prophet/App.pm
Log:
r56123 at onn: sartak | 2008-05-17 02:59:24 -0400
Moosify Prophet::App
Modified: Prophet/branches/moose/Makefile.PL
==============================================================================
--- Prophet/branches/moose/Makefile.PL (original)
+++ Prophet/branches/moose/Makefile.PL Sat May 17 02:59:29 2008
@@ -24,6 +24,7 @@
requires('File::Find::Rule');
requires('Proc::InvokeEditor');
requires('Scalar::Defer');
+requires('Moose');
features(
'REST Server' => [
Modified: Prophet/branches/moose/lib/Prophet/App.pm
==============================================================================
--- Prophet/branches/moose/lib/Prophet/App.pm (original)
+++ Prophet/branches/moose/lib/Prophet/App.pm Sat May 17 02:59:29 2008
@@ -1,10 +1,42 @@
-use warnings;
-use strict;
-
package Prophet::App;
-use base qw/Class::Accessor/;
+use Moose;
use Path::Class;
-__PACKAGE__->mk_accessors(qw/_resdb_handle _config/);
+
+has handle => (
+ is => 'rw',
+ isa => 'Prophet::Replica',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ my $root = $ENV{'PROPHET_REPO'} || dir($ENV{'HOME'}, '.prophet');
+ my $type = $self->default_replica_type;
+ return Prophet::Replica->new({ url => $type.':file://' . $root });
+ },
+);
+
+has resdb_handle => (
+ is => 'rw',
+ isa => 'Prophet::Replica',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ return $self->handle->resolution_db_handle
+ if $self->handle->resolution_db_handle;
+ my $root = ($ENV{'PROPHET_REPO'} || dir($ENV{'HOME'}, '.prophet')) . "_res";
+ my $type = $self->default_replica_type;
+ return Prophet::Replica->new({ url => $type.':file://' . $root });
+ },
+);
+
+has _config => (
+ is => 'rw',
+ isa => 'Prophet::Config',
+ lazy => 1,
+ default => sub {
+ require Prophet::Config;
+ return Prophet::Config->new;
+ },
+);
use constant DEFAULT_REPLICA_TYPE => 'prophet';
@@ -14,73 +46,27 @@
=cut
-sub _handle {
+sub BUILD {
my $self = shift;
- $self->{_handle} = shift if (@_);
- return $self->{_handle};
-}
-
-sub new {
- my $self = shift->SUPER::new(@_);
-
$self->_load_replica_types();
-
- # Initialize our handle and resolution db handle
- $self->handle;
- $self->resdb_handle;
-
- return $self;
}
sub _load_replica_types {
my $self = shift;
- my $replica_class = ref($self)."::Replica";
- my $except = $replica_class."::(.*)::";
- Module::Pluggable->import( search_path => $replica_class, sub_name => 'app_replica_types', require => 0, except => qr/$except/);
- for my $package ( $self->app_replica_types) {
- $package->require;
+ my $replica_class = blessed($self)."::Replica";
+ my $except = $replica_class."::(.*)::";
+ Module::Pluggable->import( search_path => $replica_class, sub_name => 'app_replica_types', require => 0, except => qr/$except/);
+ for my $package ( $self->app_replica_types) {
+ $package->require;
Prophet::Replica->register_replica_scheme(scheme => $package->scheme, class => $package)
- }
}
-
-sub default_replica_type {
- my $self = shift;
- return $ENV{'PROPHET_REPLICA_TYPE'} || DEFAULT_REPLICA_TYPE;
-
}
-=head2 handle
-
-
-=cut
-
-sub handle {
- my $self = shift;
- unless ( $self->_handle() ) {
- my $root = $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' );
- my $type = $self->default_replica_type;
- $self->_handle( Prophet::Replica->new( { url => $type.':file://' . $root } ) );
- }
- return $self->_handle();
-}
-
-=head2 resdb_handle
-
-=cut
-
-sub resdb_handle {
+sub default_replica_type {
my $self = shift;
-
- return ($self->handle->resolution_db_handle) if ($self->handle->resolution_db_handle);
- unless ( $self->_resdb_handle ) {
- my $root = ( $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' ) ) . "_res";
- my $type = $self->default_replica_type;
- $self->_resdb_handle( Prophet::Replica->new( { url => $type.':file://' . $root } ) );
- }
- return $self->_resdb_handle();
+ return $ENV{'PROPHET_REPLICA_TYPE'} || DEFAULT_REPLICA_TYPE;
}
-
sub require_module {
my $self = shift;
my $class = shift;
@@ -107,11 +93,6 @@
sub config {
my $self = shift;
- unless ($self->_config) {
- require Prophet::Config;
- $self->_config(Prophet::Config->new);
- }
-
return $self->_config if @_ == 0;
my $key = shift;
@@ -121,4 +102,7 @@
return $self->_config->set($key => $value);
}
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
1;
More information about the Bps-public-commit
mailing list