|  |  
 |   |   
 NAMEXS::Object::Magic - Opaque, extensible XS pointer backed objects using "sv_magic" VERSIONversion 0.05 SYNOPSIS        package MyObject;
        use XS::Object::Magic;
        sub new {
                my $class = shift;
                # create any object representation you like
                my $self = bless {}, $class;
                $self->build_struct;
                return $self;
        }
        # or using Moose
        package MyObject;
        use Moose;
        sub BUILD {
                shift->build_struct;
        }
        # then in XS
        MODULE = MyObject  PACKAGE = MyObject
        void build_struct (SV *self)
                PREINIT:
                        my_struct_t *thingy;
                CODE:
                        thingy = create_whatever();
                        /* note that we dereference self first. This
                         * can be done using an XS typemap of course */
                        xs_object_magic_attach_struct(aTHX_ SvRV(self), thingy);
        void foo (SV *self)
                PREINIT:
                        my_struct_t *thingy;
                INIT:
                        thingy = xs_object_magic_get_struct_rv(aTHX_ self);
                CODE:
                        my_struct_foo(thingy); /* delegate to C api */
        /* using typemap */
        void foo (my_struct_t *thingy)
                CODE:
                        my_struct_foo(thingy);
        /* or better yet */
        PREFIX = my_struct_
        void
        my_struct_foo (thingy)
                my_struct_t *thingy;
        /* don't forget a destructor */
        void
        DESTROY (my_struct_t *thingy)
                CODE:
                        Safefree(thingy);
                        /* note that xs_object_magic_get_struct() will
                         * still return a pointe which is now invalid */
DESCRIPTIONThis way of associating structs with Perl space objects is designed to supersede Perl's builtin "T_PTROBJ" with something that is designed to be: 
 C API
 TYPEMAPThe included typemap provides a "T_PTROBJ_MG" entry which only supports the "INPUT" conversion. This typemap entry lets you declare methods that are invoked directly on the associated pointer. In your own typemap add an entry:         TYPEMAP
        my_pointer_t *  T_PTROBJ_MG
and then you can use "my_pointer_t" as the argument type of the invocant:         I32
        method (self)
                my_pointer_t *self;
                CODE:
                        ...
Note that there is no "OUTPUT" conversion. In order to return your object you need to use ST(0) or some other means of getting the invocant. SUPPORTBugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=XS-Object-Magic> (or bug-XS-Object-Magic@rt.cpan.org <mailto:bug-XS-Object-Magic@rt.cpan.org>). AUTHORיובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> CONTRIBUTORS
 COPYRIGHT AND LICENCEThis software is copyright (c) 2009 by יובל קוג'מן (Yuval Kogman). This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 
 
 |