Revision history for Class::Accessor::Grouped.
+0.05001 Thur May 10 20:55:11 2007
+ - set_component_class now only dies if the specified class is a
+ installed/installable class and fails to load it.
+
0.05000 Tue May 08 19:42:33 2007
- Added get/set_component_class
use Carp;
use Class::Inspector ();
use Class::ISA ();
-use Scalar::Util ();
+use Scalar::Util qw/reftype blessed/;
use vars qw($VERSION);
-$VERSION = '0.05000';
+$VERSION = '0.05001';
=head1 NAME
sub _mk_group_accessors {
my($self, $maker, $group, @fields) = @_;
- my $class = Scalar::Util::blessed($self) || $self;
+ my $class = blessed $self || $self;
# So we don't have to do lots of lookups inside the loop.
$maker = $self->can($maker) unless ref $maker;
my ($self, $get) = @_;
my $class;
- if (Scalar::Util::blessed($self)) {
- my $reftype = Scalar::Util::reftype($self);
+ if (blessed $self) {
+ my $reftype = reftype $self;
$class = ref $self;
if ($reftype eq 'HASH' && exists $self->{$get}) {
sub set_inherited {
my ($self, $set, $val) = @_;
- if (Scalar::Util::blessed($self)) {
- if (Scalar::Util::reftype($self) eq 'HASH') {
+ if (blessed $self) {
+ if (reftype $self eq 'HASH') {
return $self->{$set} = $val;
} else {
croak('Cannot set inherited value on an object instance that is not hash-based');
my ($self, $field, $value) = @_;
if ($value) {
- if (!Class::Inspector->loaded($value)) {
+ if (Class::Inspector->installed($value) && !Class::Inspector->loaded($value)) {
eval "use $value";
croak("Could not load $field '$value': ", $@) if $@;
=cut
sub get_super_paths {
- my $class = Scalar::Util::blessed $_[0] || $_[0];
+ my $class = blessed $_[0] || $_[0];
return Class::ISA::super_path($class);
};
-use Test::More tests => 7;
+use Test::More tests => 8;
use strict;
use warnings;
use lib 't/lib';
is(AccessorGroups->result_class, undef);
-# croak on set where class can't be loaded
+## croak on set where class can't be loaded and it's a physical class
my $dying = AccessorGroups->new;
eval {
- $dying->result_class('Junkies');
+ $dying->result_class('NotReallyAClass');
};
-ok($@ =~ /Could not load result_class 'Junkies'/);
+ok($@ =~ /Could not load result_class 'NotReallyAClass'/);
is($dying->result_class, undef);
+
+## don't croak when the class isn't available but not loaded for people
+## who create class/packages on the fly
+$dying->result_class('JunkiesNeverInstalled');
+is($dying->result_class, 'JunkiesNeverInstalled');
+
ok(!Class::Inspector->loaded('BaseInheritedGroups'));
AccessorGroups->result_class('BaseInheritedGroups');
ok(Class::Inspector->loaded('BaseInheritedGroups'));
## finally run under -T. Until then, I'm on my own here. ;-)
my @files;
my %trusted = (
-
+ 'NotReallyAClass.pm' => 1
);
find({ wanted => \&wanted,
## finally run under -T. Until then, I'm on my own here. ;-)
my @files;
my %trusted = (
-
+ 'NotReallyAClass.pm' => 1
);
find({ wanted => \&wanted,