Skip to content

Commit

Permalink
yank Rose dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Karman committed Apr 7, 2014
1 parent 327f8c7 commit ed95ad2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -20,7 +20,7 @@ WriteMakefile(
PREREQ_PM => {
'Search::Query' => '0.18',
'Encode' => '0',
'Rose::ObjectX::CAF' => '0.03',
'Class::XSAccessor' => '0.14',
'Data::Dump' => 0,
'File::Slurp' => 0,
'Test::More' => 0.94,
Expand Down
79 changes: 0 additions & 79 deletions lib/Search/Tools/MethodMaker.pm

This file was deleted.

84 changes: 74 additions & 10 deletions lib/Search/Tools/Object.pm
Expand Up @@ -2,14 +2,13 @@ package Search::Tools::Object;
use strict;
use warnings;
use Carp;
use base qw( Rose::ObjectX::CAF );
use Scalar::Util qw( blessed );
use Search::Tools::MethodMaker;

our $VERSION = '0.99';
use Class::XSAccessor;

__PACKAGE__->mk_accessors(qw( debug ));

our $VERSION = '0.99';

=pod
=head1 NAME
Expand Down Expand Up @@ -42,10 +41,14 @@ Search::Tools::Object - base class for Search::Tools objects
=head1 DESCRIPTION
Search::Tools::Object is a subclass of Rose::Object. Prior to version 0.24
STO was a subclass of Class::Accessor::Fast. Backwards compatability for
the mk_accessors() and mk_ro_accessors() class methods are preserved
via Search::Tools::MethodMaker.
Search::Tools::Object uses Class::XSAccessor.
Prior to version 1.00 STO was a subclass of Rose::ObjectX::CAF.
Prior to version 0.24 STO was a subclass of Class::Accessor::Fast.
Backwards compatability for the mk_accessors() and mk_ro_accessors()
class methods are preserved.
=head1 METHODS
Expand All @@ -55,9 +58,22 @@ sub _init {
croak "use init() instead";
}

=head2 new( I<args> )
Constructor. Do not override this method. Override init() instead.
=cut

sub new {
my $class = shift;
my $self = bless {}, $class;
$self->init( @_ > 1 ? @_ : %{ $_[0] } );
return $self;
}

=head2 init
Overrides base Rose::Object method. Rather than calling
Initialize objects. Override init() instead of new(). Rather than calling
the method name for each param passed in new(), the value
is simply set in the object as a hash ref. This assumes
every Search::Tools::Object is a blessed hash ref.
Expand All @@ -70,11 +86,59 @@ if init() tried to set values with them.

sub init {
my $self = shift(@_);
$self->SUPER::init(@_);
$self->__init(@_);
$self->{debug} ||= $ENV{PERL_DEBUG} || 0;
return $self;
}

sub __init {
my $self = shift;

# assume object is hash and set key
# rather than call method, since we have read-only methods.
while (@_) {
my $method = shift;
if ( !$self->can($method) ) {
croak "No such method $method";
}
$self->{$method} = shift;
}

return $self;
}

=head2 mk_accessors( I<names> )
CAF-like method for back-compat with versions < 1.00.
=cut

sub mk_accessors {
my $class = shift;
for my $attr (@_) {
Class::XSAccessor->import(
accessors => { $attr => $attr },
class => $class,
);
}
}

=head2 mk_ro_accessors( I<names> )
CAF-like method for back-compat with versions < 1.00.
=cut

sub mk_ro_accessors {
my $class = shift;
for my $attr (@_) {
Class::XSAccessor->import(
getters => { $attr => $attr },
class => $class,
);
}
}

=head2 debug( I<n> )
Get/set the debug value for the object. All objects inherit this attribute.
Expand Down

0 comments on commit ed95ad2

Please sign in to comment.