From: Yuval Kogman Date: Wed, 20 Aug 2008 10:43:48 +0000 (+0000) Subject: rename getter/setter to reader/writer for consistency X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=24a7a8c513b5a60bfdf1eb5f3e539e9d16453702;p=gitmo%2FMoose.git rename getter/setter to reader/writer for consistency --- diff --git a/Moose.xs b/Moose.xs index f5d4b57..55a71e8 100644 --- a/Moose.xs +++ b/Moose.xs @@ -785,7 +785,7 @@ STATIC SV *deinitialize_slot(pTHX_ SV *self, ATTR *attr) { return hv_delete_ent((HV *)SvRV(self), attr->slot_sv, 0, attr->slot_u32); } -STATIC void setter_common(pTHX_ SV *self, ATTR *attr, SV *value); +STATIC void writer_common(pTHX_ SV *self, ATTR *attr, SV *value); STATIC SV *get_default(pTHX_ SV *self, ATTR *attr) { @@ -835,21 +835,21 @@ STATIC SV *get_default(pTHX_ SV *self, ATTR *attr) { return NULL; } -STATIC SV *getter_common(pTHX_ SV *self, ATTR *attr) { +STATIC SV *reader_common(pTHX_ SV *self, ATTR *attr) { SV *value = get_slot_value(aTHX_ self, attr); if ( value ) { return value; } else if ( ATTR_ISLAZY(attr) ) { value = get_default(aTHX_ self, attr); - setter_common(aTHX_ self, attr, value); + writer_common(aTHX_ self, attr, value); return value; } return NULL; } -STATIC void setter_common(pTHX_ SV *self, ATTR *attr, SV *value) { +STATIC void writer_common(pTHX_ SV *self, ATTR *attr, SV *value) { if ( ATTR_TYPE(attr) ) { if ( !check_type_constraint(aTHX_ ATTR_TYPE(attr), attr->tc_check, attr->type_constraint, value) ) croak("Bad param"); @@ -860,8 +860,8 @@ STATIC void setter_common(pTHX_ SV *self, ATTR *attr, SV *value) { /* simple high level api */ -STATIC XS(getter); -STATIC XS(getter) +STATIC XS(reader); +STATIC XS(reader) { #ifdef dVAR dVAR; @@ -875,7 +875,7 @@ STATIC XS(getter) SP -= items; - value = getter_common(aTHX_ ST(0), attr); + value = reader_common(aTHX_ ST(0), attr); if (value) { ST(0) = sv_mortalcopy(value); /* mortalcopy because $_ .= "blah" for $foo->bar */ @@ -885,8 +885,8 @@ STATIC XS(getter) } } -STATIC XS(setter); -STATIC XS(setter) +STATIC XS(writer); +STATIC XS(writer) { #ifdef dVAR dVAR; @@ -899,7 +899,7 @@ STATIC XS(setter) SP -= items; - setter_common(aTHX_ ST(0), attr, ST(1)); + writer_common(aTHX_ ST(0), attr, ST(1)); ST(0) = ST(1); /* return value */ XSRETURN(1); @@ -920,10 +920,10 @@ STATIC XS(accessor) SP -= items; if (items > 1) { - setter_common(aTHX_ ST(0), attr, ST(1)); + writer_common(aTHX_ ST(0), attr, ST(1)); ST(0) = ST(1); /* return value */ } else { - SV *value = getter_common(aTHX_ ST(0), attr); + SV *value = reader_common(aTHX_ ST(0), attr); if ( value ) { ST(0) = value; } else { @@ -955,16 +955,16 @@ STATIC XS(predicate) } enum xs_body { - xs_body_getter = 0, - xs_body_setter, + xs_body_reader = 0, + xs_body_writer, xs_body_accessor, xs_body_predicate, max_xs_body }; STATIC XSPROTO ((*xs_bodies[])) = { - getter, - setter, + reader, + writer, accessor, predicate, }; @@ -977,8 +977,8 @@ new_sub(attr, name) SV *attr; SV *name; ALIAS: - new_getter = xs_body_getter - new_setter = xs_body_setter + new_reader = xs_body_reader + new_writer = xs_body_writer new_accessor = xs_body_accessor new_predicate = xs_body_predicate PREINIT: diff --git a/t/700_xs/001_basic.t b/t/700_xs/001_basic.t index 1be2c15..6afc5df 100644 --- a/t/700_xs/001_basic.t +++ b/t/700_xs/001_basic.t @@ -96,8 +96,8 @@ BEGIN { } } -ok( defined &Moose::XS::new_getter, "new_getter" ); -ok( defined &Moose::XS::new_setter, "new_setter" ); +ok( defined &Moose::XS::new_reader, "new_reader" ); +ok( defined &Moose::XS::new_writer, "new_writer" ); ok( defined &Moose::XS::new_accessor, "new_accessor" ); ok( defined &Moose::XS::new_predicate, "new_predicate" ); @@ -114,7 +114,7 @@ ok( defined &Moose::XS::new_predicate, "new_predicate" ); has x => ( is => "rw", predicate => "has_x" ); has y => ( is => "ro" ); - has z => ( reader => "z", setter => "set_z" ); + has z => ( reader => "z", writer => "set_z" ); has ref => ( is => "rw", weak_ref => 1 ); has i => ( isa => "Int", is => "rw" ); has s => ( isa => "Str", is => "rw" ); @@ -146,9 +146,9 @@ ok( defined &Moose::XS::new_predicate, "new_predicate" ); my ( $x, $y, $z, $ref, $a, $s, $i, $o, $f, $c, $b ) = map { Foo->meta->get_attribute($_) } qw(x y z ref a s i o f c b); $x->Moose::XS::new_accessor("Foo::x"); $x->Moose::XS::new_predicate("Foo::has_x"); - $y->Moose::XS::new_getter("Foo::y"); - $z->Moose::XS::new_getter("Foo::z"); - $z->Moose::XS::new_setter("Foo::set_z"); + $y->Moose::XS::new_reader("Foo::y"); + $z->Moose::XS::new_reader("Foo::z"); + $z->Moose::XS::new_writer("Foo::set_z"); $ref->Moose::XS::new_accessor("Foo::ref"); $a->Moose::XS::new_accessor("Foo::a"); $s->Moose::XS::new_accessor("Foo::s");