Add examples for methods that get used most often
[p5sagit/Class-Accessor-Grouped.git] / lib / Class / Accessor / Grouped.pm
index 8bbce64..77c5575 100644 (file)
@@ -3,16 +3,24 @@ use strict;
 use warnings;
 use Carp ();
 use Scalar::Util ();
-use MRO::Compat;
 
-our $VERSION = '0.10001';
+BEGIN {
+  if ($] < 5.009_005) {
+    require MRO::Compat;
+  }
+  else {
+    require mro;
+  }
+}
+
+our $VERSION = '0.10002';
 $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
 
 # when changing minimum version don't forget to adjust L</PERFORMANCE> and
 # the Makefile.PL as well
 our $__minimum_xsa_version;
 BEGIN {
-    $__minimum_xsa_version = '1.06';
+    $__minimum_xsa_version = '1.11';
 }
 
 our $USE_XS;
@@ -72,6 +80,14 @@ Class::Accessor::Grouped - Lets you build groups of accessors
 
 =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
@@ -81,6 +97,8 @@ getters and setters.
 
 =head2 mk_group_accessors
 
+ __PACKAGE__->mk_group_accessors(simple => 'hair_length');
+
 =over 4
 
 =item Arguments: $group, @fieldspec
@@ -113,6 +131,8 @@ sub mk_group_accessors {
 
 =head2 mk_group_ro_accessors
 
+ __PACKAGE__->mk_group_ro_accessors(simple => 'birthdate');
+
 =over 4
 
 =item Arguments: $group, @fieldspec
@@ -135,6 +155,8 @@ sub mk_group_ro_accessors {
 
 =head2 mk_group_wo_accessors
 
+ __PACKAGE__->mk_group_wo_accessors(simple => 'lie');
+
 =over 4
 
 =item Arguments: $group, @fieldspec
@@ -157,6 +179,8 @@ sub mk_group_wo_accessors {
 
 =head2 make_group_accessor
 
+ __PACKAGE__->make_group_accessor(simple => 'hair_length', 'hair_length');
+
 =over 4
 
 =item Arguments: $group, $field, $method
@@ -175,6 +199,8 @@ sub make_group_accessor { $gen_accessor->('rw', @_) }
 
 =head2 make_group_ro_accessor
 
+ __PACKAGE__->make_group_ro_accessor(simple => 'birthdate', 'birthdate');
+
 =over 4
 
 =item Arguments: $group, $field, $method
@@ -193,6 +219,8 @@ sub make_group_ro_accessor { $gen_accessor->('ro', @_) }
 
 =head2 make_group_wo_accessor
 
+ __PACKAGE__->make_group_wo_accessor(simple => 'lie', 'lie');
+
 =over 4
 
 =item Arguments: $group, $field, $method
@@ -410,8 +438,7 @@ To provide total flexibility L<Class::Accessor::Grouped> calls methods
 internally while performing get/set actions, which makes it noticeably
 slower than similar modules. To compensate, this module will automatically
 use the insanely fast L<Class::XSAccessor> to generate the C<simple>-group
-accessors, if L<< Class::XSAccessor >= 1.06|Class::XSAccessor >> is
-available on your system.
+accessors if this module is available on your system.
 
 =head2 Benchmark
 
@@ -454,12 +481,6 @@ an object, invoke a simple accessor on that object, and B<then> manipulate
 the symbol table to install a C<get/set_simple> override - you get to keep
 all the pieces.
 
-While L<Class::XSAccessor> works surprisingly well for the amount of black
-magic it tries to pull off, it's still black magic. At present (Sep 2010)
-the module is known to have problems on Windows under heavy thread-stress
-(e.g. Win32+Apache+mod_perl). Thus for the time being L<Class::XSAccessor>
-will not be used automatically if you are running under C<MSWin32>.
-
 =head1 AUTHORS
 
 Matt S. Trout <mst@shadowcatsystems.co.uk>
@@ -470,6 +491,8 @@ Christopher H. Laco <claco@chrislaco.com>
 
 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>
@@ -553,12 +576,9 @@ BEGIN {
 }
 
 # Autodetect unless flag supplied
-# Class::XSAccessor is segfaulting on win32, in some
-# esoteric heavily-threaded scenarios
-# Win32 users can set $USE_XS/CAG_USE_XS to try to use it anyway
 my $xsa_autodetected;
 if (! defined $USE_XS) {
-  $USE_XS = (!__CAG_NO_CXSA and $^O ne 'MSWin32') ? 1 : 0;
+  $USE_XS = __CAG_NO_CXSA ? 0 : 1;
   $xsa_autodetected++;
 }
 
@@ -699,7 +719,7 @@ $gen_accessor = sub {
       # if after this shim was created someone wrapped it with an 'around',
       # we can not blindly reinstall the method slot - we will destroy the
       # wrapper. Silently chain execution further...
-      if ($expected_cref != $current_class->can($methname)) {
+      if ( !$expected_cref or $expected_cref != $current_class->can($methname) ) {
 
         # there is no point in re-determining it on every subsequent call,
         # just store for future reference