}
}
-our $VERSION = '0.10002';
+our $VERSION = '0.10003';
$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
# when changing minimum version don't forget to adjust L</PERFORMANCE> and
=head1 SYNOPSIS
+ use base 'Class::Accessor::Grouped';
+
+ # make basic accessors for objects
+ __PACKAGE__->mk_group_accessors(simple => qw(id name email));
+
+ # make accessor that works for objects and classes
+ __PACKAGE__->mk_group_accessors(inherited => 'awesome_level');
+
=head1 DESCRIPTION
This class lets you build groups of accessors that will call different
=head2 mk_group_accessors
+ __PACKAGE__->mk_group_accessors(simple => 'hair_length', [ hair_color => 'hc' ]);
+
=over 4
=item Arguments: $group, @fieldspec
=head2 mk_group_ro_accessors
+ __PACKAGE__->mk_group_ro_accessors(simple => 'birthdate', [ social_security_number => 'ssn' ]);
+
=over 4
=item Arguments: $group, @fieldspec
=head2 mk_group_wo_accessors
+ __PACKAGE__->mk_group_wo_accessors(simple => 'lie', [ subject => 'subj' ]);
+
=over 4
=item Arguments: $group, @fieldspec
$self->_mk_group_accessors('make_group_wo_accessor', $group, @fields);
}
-=head2 make_group_accessor
-
-=over 4
-
-=item Arguments: $group, $field, $method
-
-Returns: \&accessor_coderef ?
-
-=back
-
-Called by mk_group_accessors for each entry in @fieldspec. Either returns
-a coderef which will be installed at C<&__PACKAGE__::$method>, or returns
-C<undef> if it elects to install the coderef on its own.
-
-=cut
-
-sub make_group_accessor { $gen_accessor->('rw', @_) }
-
-=head2 make_group_ro_accessor
-
-=over 4
-
-=item Arguments: $group, $field, $method
-
-Returns: \&accessor_coderef ?
-
-=back
-
-Called by mk_group_ro_accessors for each entry in @fieldspec. Either returns
-a coderef which will be installed at C<&__PACKAGE__::$method>, or returns
-C<undef> if it elects to install the coderef on its own.
-
-=cut
-
-sub make_group_ro_accessor { $gen_accessor->('ro', @_) }
-
-=head2 make_group_wo_accessor
-
-=over 4
-
-=item Arguments: $group, $field, $method
-
-Returns: \&accessor_coderef ?
-
-=back
-
-Called by mk_group_wo_accessors for each entry in @fieldspec. Either returns
-a coderef which will be installed at C<&__PACKAGE__::$method>, or returns
-C<undef> if it elects to install the coderef on its own.
-
-=cut
-
-sub make_group_wo_accessor { $gen_accessor->('wo', @_) }
-
=head2 get_simple
=over 4
return $_[0]->set_inherited($_[1], $_[2]);
};
+=head1 INTERNAL METHODS
+
+These methods are documented for clarity, but are never meant to be called
+directly, and are not really meant for overriding either.
+
=head2 get_super_paths
-Returns a list of 'parent' or 'super' class names that the current class inherited from.
+Returns a list of 'parent' or 'super' class names that the current class
+inherited from. This is what drives the traversal done by L</get_inherited>.
=cut
return @{mro::get_linear_isa( ref($_[0]) || $_[0] )};
};
+=head2 make_group_accessor
+
+ __PACKAGE__->make_group_accessor('simple', 'hair_length', 'hair_length');
+ __PACKAGE__->make_group_accessor('simple', 'hc', 'hair_color');
+
+=over 4
+
+=item Arguments: $group, $field, $accessor
+
+Returns: \&accessor_coderef ?
+
+=back
+
+Called by mk_group_accessors for each entry in @fieldspec. Either returns
+a coderef which will be installed at C<&__PACKAGE__::$accessor>, or returns
+C<undef> if it elects to install the coderef on its own.
+
+=cut
+
+sub make_group_accessor { $gen_accessor->('rw', @_) }
+
+=head2 make_group_ro_accessor
+
+ __PACKAGE__->make_group_ro_accessor('simple', 'birthdate', 'birthdate');
+ __PACKAGE__->make_group_ro_accessor('simple', 'ssn', 'social_security_number');
+
+=over 4
+
+=item Arguments: $group, $field, $accessor
+
+Returns: \&accessor_coderef ?
+
+=back
+
+Called by mk_group_ro_accessors for each entry in @fieldspec. Either returns
+a coderef which will be installed at C<&__PACKAGE__::$accessor>, or returns
+C<undef> if it elects to install the coderef on its own.
+
+=cut
+
+sub make_group_ro_accessor { $gen_accessor->('ro', @_) }
+
+=head2 make_group_wo_accessor
+
+ __PACKAGE__->make_group_wo_accessor('simple', 'lie', 'lie');
+ __PACKAGE__->make_group_wo_accessor('simple', 'subj', 'subject');
+
+=over 4
+
+=item Arguments: $group, $field, $accessor
+
+Returns: \&accessor_coderef ?
+
+=back
+
+Called by mk_group_wo_accessors for each entry in @fieldspec. Either returns
+a coderef which will be installed at C<&__PACKAGE__::$accessor>, or returns
+C<undef> if it elects to install the coderef on its own.
+
+=cut
+
+sub make_group_wo_accessor { $gen_accessor->('wo', @_) }
+
+
=head1 PERFORMANCE
To provide total flexibility L<Class::Accessor::Grouped> calls methods
Caelum: Rafael Kitover <rkitover@cpan.org>
+frew: Arthur Axel "fREW" Schmidt <frioux@gmail.com>
+
groditi: Guillermo Roditi <groditi@cpan.org>
Jason Plum <jason.plum@bmmsi.com>
delete $INC{'Sub/Name.pm'}; # because older perls suck
$@;
};
- *__CAG_NO_SUBNAME = $err
+ *__CAG_ENV__::NO_SUBNAME = $err
? sub () { $err }
: sub () { 0 }
;
delete $INC{'Class/XSAccessor.pm'};
$@;
};
- *__CAG_NO_CXSA = $err
+ *__CAG_ENV__::NO_CXSA = $err
? sub () { $err }
: sub () { 0 }
;
- *__CAG_BROKEN_GOTO = ($] < '5.008009')
+ *__CAG_ENV__::BROKEN_GOTO = ($] < '5.008009')
? sub () { 1 }
: sub () { 0 }
;
- *__CAG_UNSTABLE_DOLLARAT = ($] < '5.013002')
+ *__CAG_ENV__::UNSTABLE_DOLLARAT = ($] < '5.013002')
? sub () { 1 }
: sub () { 0 }
;
- *__CAG_TRACK_UNDEFER_FAIL = (
+ *__CAG_ENV__::TRACK_UNDEFER_FAIL = (
$INC{'Test/Builder.pm'} || $INC{'Test/Builder2.pm'}
and
$0 =~ m|^ x?t / .+ \.t $|x
# Autodetect unless flag supplied
my $xsa_autodetected;
if (! defined $USE_XS) {
- $USE_XS = __CAG_NO_CXSA ? 0 : 1;
+ $USE_XS = __CAG_ENV__::NO_CXSA ? 0 : 1;
$xsa_autodetected++;
}
# Thus the final method (properly labeled and all) is installed in the
# calling-package's namespace
if ($USE_XS and $group eq 'simple') {
- die sprintf( "Class::XSAccessor requested but not available:\n%s\n", __CAG_NO_CXSA )
- if __CAG_NO_CXSA;
+ die sprintf( "Class::XSAccessor requested but not available:\n%s\n", __CAG_ENV__::NO_CXSA )
+ if __CAG_ENV__::NO_CXSA;
my ($expected_cref, $cached_implementation);
my $ret = $expected_cref = sub {
# older perls segfault if the cref behind the goto throws
# http://rt.perl.org/rt3/Public/Bug/Display.html?id=35878
- return $resolved_implementation->(@_) if __CAG_BROKEN_GOTO;
+ return $resolved_implementation->(@_) if __CAG_ENV__::BROKEN_GOTO;
goto $resolved_implementation;
}
- if (__CAG_TRACK_UNDEFER_FAIL) {
+ if (__CAG_ENV__::TRACK_UNDEFER_FAIL) {
my $deferred_calls_seen = do {
no strict 'refs';
\%{"${current_class}::__cag_deferred_xs_shim_invocations"}
# older perls segfault if the cref behind the goto throws
# http://rt.perl.org/rt3/Public/Bug/Display.html?id=35878
- return $resolved_implementation->(@_) if __CAG_BROKEN_GOTO;
+ return $resolved_implementation->(@_) if __CAG_ENV__::BROKEN_GOTO;
goto $resolved_implementation;
};
}
# no Sub::Name - just install the coderefs directly (compiling every time)
- elsif (__CAG_NO_SUBNAME) {
+ elsif (__CAG_ENV__::NO_SUBNAME) {
my $src = $accessor_maker_cache->{source}{$type}{$group}{$field} ||=
$maker_templates->{$type}{pp_code}->($group, $field);
no warnings 'redefine';
- local $@ if __CAG_UNSTABLE_DOLLARAT;
+ local $@ if __CAG_ENV__::UNSTABLE_DOLLARAT;
eval "sub ${class}::${methname} { $src }";
undef; # so that no further attempt will be made to install anything
my $src = $accessor_maker_cache->{source}{$type}{$group}{$field} ||=
$maker_templates->{$type}{pp_code}->($group, $field);
- local $@ if __CAG_UNSTABLE_DOLLARAT;
+ local $@ if __CAG_ENV__::UNSTABLE_DOLLARAT;
eval "sub { my \$dummy; sub { \$dummy if 0; $src } }" or die $@;
})->()
}