Skip to content

Commit

Permalink
Class::MOP -> Class::Load
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Fields committed Jul 15, 2012
1 parent 083e88f commit e69cd0b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 66 deletions.
1 change: 0 additions & 1 deletion lib/Biome.pm
Expand Up @@ -3,7 +3,6 @@ package Biome;
our $VERSION = '0.001';

use Modern::Perl;
use Class::MOP;
use Moose ();
use Moose::Exporter;

Expand Down
47 changes: 24 additions & 23 deletions lib/Biome/Meta/Class.pm
@@ -1,6 +1,7 @@
package Biome::Meta::Class;

use Moose;
use Class::Load ();

extends 'Moose::Meta::Class';

Expand All @@ -20,7 +21,7 @@ sub throw_error {

sub raise_error {
my ( $self, @args ) = @_;
if (($args[0]->isa('Exception::Class::Base') ||
if (($args[0]->isa('Exception::Class::Base') ||
$args[0]->isa('Error::Base'))) {
$args[0]->throw(@args);
} else {
Expand All @@ -31,72 +32,72 @@ sub raise_error {

sub create_error {
my ( $self, @args ) = @_;

my $text;
local $error_level = ($error_level || 0 ) + 1;
local $error_level = ($error_level || 0 ) + 1;
if ( @args % 2 == 1 ) {
$text = shift @args;
}

my %args = (@args );

$text ||= $args{message} || "Something's wrong!";

my $class = $args{class} || $self->error_class;

# we add stack trace and extra stuff only for core Biome ex. class for the
# time being

if ($class->isa('Biome::Meta::Error')) {
@args{qw(metaclass last_error)} = ($self, $@);
my $std = $self->stack_trace_dump();
my $title = "------------- EXCEPTION $class -------------";
my $footer = ('-' x CORE::length($title))."\n";
my $msg = "\n$title\n". "MSG: $text\n". $std. $footer."\n";

$args{message} = $msg;
}
$args{depth} += $error_level;
Class::MOP::load_class($class);

Class::Load::load_class($class);
require Carp::Heavy;

# Exception::Class dies unless you pass specific params, so white-list them
my $exception = $class->isa('Exception::Class::Base') ?
my $exception = $class->isa('Exception::Class::Base') ?
$class->new(
@args{qw(message)}
) :
$class->new(
Carp::caller_info($args{depth}),
%args
) ;
) ;

}

sub stack_trace_dump{
my ($self) = @_;

my @stack = $self->stack_trace();

shift @stack;
shift @stack;
shift @stack;

my $out;
my ($module,$function,$file,$position);


foreach my $stack ( @stack) {
($module,$file,$position,$function) = @{$stack};
$out .= "STACK $function $file:$position\n";
}

return $out;
}

sub stack_trace{
my ($self) = @_;

my $i = 0;
my @out = ();
my $prev = [];
Expand All @@ -122,4 +123,4 @@ __PACKAGE__->meta->make_immutable(inline_constructor => 0);

__END__
ALL POD HERE
ALL POD HERE
18 changes: 9 additions & 9 deletions lib/Biome/Role/Delegate.pm
Expand Up @@ -15,20 +15,20 @@ role {
defined $delegate_map->{isa};
my $cons = $delegate_map->{constructor} || 'new';
delete $delegate_map->{constructor};

# delegated to methods lazily load classes. This can probably
$delegate_map->{default} //= sub {
Class::MOP::load_class($delegate_map->{isa})
if !Class::MOP::is_class_loaded($delegate_map->{isa});
Class::Load::load_class($delegate_map->{isa})
if !Class::Load::is_class_loaded($delegate_map->{isa});
$delegate_map->{default_params} ?
$delegate_map->{isa}->$cons($delegate_map->{default_params}) :
$delegate_map->{isa}->$cons();
};
delete $delegate_map->{default_params};

$delegate_map->{handles} ||= [];
$delegate_map->{is} ||= 'rw';

has $accessor => (%$delegate_map);
}
};
Expand Down Expand Up @@ -119,12 +119,12 @@ BioPerl mailing lists. Your participation is much appreciated.
Patches are always welcome.
=head2 Support
=head2 Support
Please direct usage questions or support issues to the mailing list:
L<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and reponsive
experts will be able look at the problem and quickly address it. Please include
a thorough description of the problem with code and data examples if at all
Expand Down
51 changes: 24 additions & 27 deletions lib/Biome/Root.pm
@@ -1,13 +1,11 @@
package Biome::Root;

use Modern::Perl;
use Moose;

use Class::Load ();
extends 'Moose::Object';

#__PACKAGE__->meta->error_class('Biome::Root::Error');

use Modern::Perl;

# run BEGIN block to check for exception class, default to light output?
# or should that go in Biome?

Expand All @@ -30,27 +28,27 @@ has 'strict' => (
# this overrides the base BUILDARGS, where we deal with '-' named args
sub BUILDARGS {
my ($class, @args) = @_;

# allow hash refs
my $params;
if ( scalar(@args) % 2 ) {
if (defined $args[0] && ref $args[0] eq 'HASH') {
@args = %{$args[0]};
} else {
Class::MOP::class_of($class)->throw_error(
Class::Load::class_of($class)->throw_error(
"Odd-number of parameters passed to new(). Arguments must be ".
"named parameters or a hash reference of named parameters",
data => $args[0] );
}
}

# take care of bp-like named parameters
while( @args ) {
my $key = shift @args;
$key =~ tr/\055//d if index($key,'-') == 0; #deletes all dashes!
$params->{lc $key} = shift @args;
}

return $params;
}

Expand All @@ -70,26 +68,26 @@ sub warn {
elsif ($strict == 1) {
CORE::warn $header. $string. "\n". $self->meta->stack_trace_dump. $footer;
return;
}
}

CORE::warn $header. $string. "\n". $footer;
}

sub throw {
my ($self, @args) = @_;

# Note: value isn't passed on (not sure why, we should address that)

# This delegates to the Biome::Meta::Class throw_error(), which calls
# proper error class. Therefore we should probably do most of the
# grunt work there so it also BP-izes the other errors that'll pop up, such
# as type check errors, etc.

my %args;

@args{qw(message class value)} = $self->rearrange([qw(TEXT CLASS VALUE)], @args);
$args{message} ||= $args[0] if @args == 1;

$self->meta->throw_error(%args);
}

Expand All @@ -107,15 +105,15 @@ sub deprecated{
# $msg .= "\nDeprecated in $version";
# if ($Biome::Root::VERSION >= $version) {
# $self->throw($msg)
# }
# }
#}
## passing this on to warn() should deal properly with verbosity issues
$self->warn($msg);
}

sub throw_not_implemented {
my $self = shift;

# this method may be supplanted by Moose's autmated system for required
# abstract role methods

Expand All @@ -133,7 +131,7 @@ sub warn_not_implemented {
sub _not_implemented_msg {
my $self = shift;
my $package = ref $self;
my $meth = (caller(2))[3]; # may not work as intended here;
my $meth = (caller(2))[3]; # may not work as intended here;
my $msg =<<EOD_NOT_IMP;
Abstract method \"$meth\" is not implemented by package $package.
This is not your fault - author of $package should be blamed!
Expand Down Expand Up @@ -183,12 +181,12 @@ sub clone {
# Module::Load::Conditional caches already loaded modules
sub load_modules {
my ($self) = shift;
Class::MOP::load_class($_) for @_;
Class::Load::load_class($_) for @_;
}

sub load_module {
my ($self, $name) = @_;
Class::MOP::load_class($name);
Class::Load::load_class($name);
}

no Moose;
Expand All @@ -205,7 +203,7 @@ __END__
Usage : $self->verbose(1)
Function: Sets verbose flag for debugging output
Returns : The current verbosity setting (0 or 1)
Args : 0 or 1 (Boolean value)
Args : 0 or 1 (Boolean value)
Status : Unstable
=cut
Expand Down Expand Up @@ -243,7 +241,7 @@ __END__
: @param : an array of parameters, either as a list (in
: which case the function simply returns the list),
: or as an associative array with hyphenated tags
: (in which case the function sorts the values
: (in which case the function sorts the values
: according to @{$order} and returns that new array.)
: The tags can be upper, lower, or mixed case
: but they must start with a hyphen (at least the
Expand All @@ -252,7 +250,7 @@ __END__
: Stein, and adapted for use in Bio::Seq by Richard Resnick and
: then adapted for use in Bio::Root::Object.pm by Steve Chervitz,
: then migrated into Bio::Root::RootI.pm by Ewan Birney.
Comments: Uppercase tags are the norm,
Comments: Uppercase tags are the norm,
: (SAC)
: This method may not be appropriate for method calls that are
: within in an inner loop if efficiency is a concern.
Expand All @@ -262,12 +260,12 @@ __END__
: @param = (-NAME=>'me', -COLOR=>'blue');
: @param = (-Name=>'me', -Color=>'blue');
: @param = ('me', 'blue');
: A leading hyphenated argument is used by this function to
: A leading hyphenated argument is used by this function to
: indicate that named parameters are being used.
: Therefore, the ('me', 'blue') list will be returned as-is.
:
: Note that Perl will confuse unquoted, hyphenated tags as
: function calls if there is a function of the same name
: Note that Perl will confuse unquoted, hyphenated tags as
: function calls if there is a function of the same name
: in the current namespace:
: -name => 'foo' is interpreted as -&name => 'foo'
:
Expand All @@ -279,7 +277,7 @@ __END__
:
: Personal note (SAC): I have found all uppercase tags to
: be more managable: it involves less single-quoting,
: the key names stand out better, and there are no method naming
: the key names stand out better, and there are no method naming
: conflicts.
: The drawbacks are that it's not as easy to type as lowercase,
: and lots of uppercase can be hard to read.
Expand All @@ -294,4 +292,3 @@ __END__
Status : Unstable (this may change into a trait for optional use)
=cut
13 changes: 7 additions & 6 deletions lib/Biome/SeqIO.pm
Expand Up @@ -3,6 +3,7 @@ package Biome::SeqIO;
use 5.010;
use Biome;
use Biome::Type::Sequence qw(Sequence_Alphabet);
use Class::Load ();
use namespace::clean -except => 'meta';

extends 'Biome::Root::IO';
Expand All @@ -25,12 +26,12 @@ sub new {
my $real_class = Scalar::Util::blessed($class) || $class;
# these all come from the same base, Moose::Object, so this is fine
my $params = $real_class->BUILDARGS(@_);

# switch out for the real class here
if (exists $params->{format}) {
my $biome_class = $real_class;
$real_class = "Biome::SeqIO::".$params->{format};
Class::MOP::load_class($real_class);
Class::Load::load_class($real_class);
$biome_class->throw("Module does not implement a sequence stream")
unless $real_class->does('Biome::Role::Stream::Seq');
} else {
Expand Down Expand Up @@ -127,12 +128,12 @@ BioPerl mailing lists. Your participation is much appreciated.
Patches are always welcome.
=head2 Support
=head2 Support
Please direct usage questions or support issues to the mailing list:
L<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and reponsive
experts will be able look at the problem and quickly address it. Please include
a thorough description of the problem with code and data examples if at all
Expand Down

0 comments on commit e69cd0b

Please sign in to comment.