unless defined $USE_XS;
BEGIN {
- package __CAG_ENV__;
+ package # hide from PAUSE
+ __CAG_ENV__;
die "Huh?! No minimum C::XSA version?!\n"
unless $__minimum_xsa_version;
$xsa_autodetected++;
}
+my $perlstring;
+if ($] < '5.008') {
+ require Data::Dumper;
+ my $d = Data::Dumper->new([])->Indent(0)->Purity(0)->Pad('')->Useqq(1)->Terse(1)->Freezer('')->Toaster('');
+ $perlstring = sub { $d->Values([shift])->Dump };
+}
+else {
+ require B;
+ $perlstring = \&B::perlstring;
+}
+
+
my $maker_templates = {
rw => {
xs_call => 'accessors',
pp_code => sub {
- my $set = "set_$_[0]";
- my $get = "get_$_[0]";
- my $field = $_[1];
- $field =~ s/'/\\'/g;
-
- "
- \@_ != 1
- ? shift->$set('$field', \@_)
- : shift->$get('$field')
- "
+ # my ($group, $fieldname) = @_;
+ my $quoted_fieldname = $perlstring->($_[1]);
+ sprintf <<'EOS', ($_[0], $quoted_fieldname) x 2;
+
+@_ > 1
+ ? shift->set_%s(%s, @_)
+ : shift->get_%s(%s)
+EOS
+
},
},
ro => {
xs_call => 'getters',
pp_code => sub {
- my $get = "get_$_[0]";
- my $field = $_[1];
- $field =~ s/'/\\'/g;
-
- "
- \@_ == 1
- ? shift->$get('$field')
- : do {
- my \$caller = caller;
- my \$class = length( ref(\$_[0]) ) ? ref(\$_[0]) : \$_[0];
- Carp::croak(\"'\$caller' cannot alter the value of '$field' \".
- \"(read-only attributes of class '\$class')\");
- }
- "
+ # my ($group, $fieldname) = @_;
+ my $quoted_fieldname = $perlstring->($_[1]);
+ sprintf <<'EOS', $_[0], $quoted_fieldname;
+
+@_ > 1
+ ? do {
+ my ($meth) = (caller(0))[3] =~ /([^\:]+)$/;
+ my $class = length( ref($_[0]) ) ? ref($_[0]) : $_[0];
+ Carp::croak(
+ "'$meth' cannot alter its value (read-only attribute of class $class)"
+ );
+ }
+ : shift->get_%s(%s)
+EOS
+
},
},
wo => {
xs_call => 'setters',
pp_code => sub {
- my $set = "set_$_[0]";
- my $field = $_[1];
- $field =~ s/'/\\'/g;
-
- "
- \@_ != 1
- ? shift->$set('$field', \@_)
- : do {
- my \$caller = caller;
- my \$class = length ( ref(\$_[0]) ) ? ref(\$_[0]) : \$_[0];
- Carp::croak(\"'\$caller' cannot access the value of '$field' \".
- \"(write-only attributes of class '\$class')\");
- }
- "
+ # my ($group, $fieldname) = @_;
+ my $quoted_fieldname = $perlstring->($_[1]);
+ sprintf <<'EOS', $_[0], $quoted_fieldname;
+
+@_ > 1
+ ? shift->set_%s(%s, @_)
+ : do {
+ my ($meth) = (caller(0))[3] =~ /([^\:]+)$/;
+ my $class = length( ref($_[0]) ) ? ref($_[0]) : $_[0];
+ Carp::croak(
+ "'$meth' cannot access its value (write-only attribute of class $class)"
+ );
+ }
+EOS
+
},
},
};