GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mojo::Base::XS(3) User Contributed Perl Documentation Mojo::Base::XS(3)

Mojo::Base::XS - very fast Mojo-styled accessors

    # Replace Mojo::Base
    use Mojo::Base::XS -infect;
    package Foo;
    use Mojo::Base;
    has foo => 'bar';
    has [qw/x y z/] => 42;
    has foo_defaults => sub { Bar->new };
    # Or use as standalone accessor generator
    package Bar;
    use Mojo::Base::XS;
    has bar => 'bar';
    has [qw/x y z/] => 42;
    has bar_defaults => sub { Baz->new };

Mojo::Base::XS also allows you to run existing applications without any modifications:

    perl -MMojo::Base::XS=-infect script/your_app

Mojo::Base::XS implements fast accessrors for Mojo-based software. Code based on Class::XSAccessor - fastes Perl accessors.

It can also be used as standalone Mojo-style accessors generator.

Mojo::Base::XS exports following functions:

    has 'name';
    has [qw/name1 name2 name3/];
    has name => 'foo';
    has name => sub {...};
    has [qw/name1 name2 name3/] => 'foo';
    has [qw/name1 name2 name3/] => sub {...};

Create attributes, just like the attr method.

Mojo::Base::XS implements following functions:

    newxs_attr('Class', 'attr');
    Class->attr(foo => 'bar');
    print Class->foo; # bar

Installs XS attribute generator subroutine

    newxs_attr('Class', 'new');
    Class->new(foo => 'bar');
    print Class->{foo}; # bar

Installs XS constructor

Inherited from Class::XSAccessors for internal use

Mojo::Base::XS implements following methods:

    my $obj = Class->new;
    my $obj = Class->new(name => 'value');
    my $obj = Class->new({name => 'value'});

This base class provides a basic object constructor. You can pass it either a hash or a hash reference with attribute values.

    __PACKAGE__->attr('name');
    __PACKAGE__->attr([qw/name1 name2 name3/]);
    __PACKAGE__->attr(name                    => 'foo');
    __PACKAGE__->attr(name                    => sub {...});
    __PACKAGE__->attr([qw/name1 name2 name3/] => 'foo');
    __PACKAGE__->attr([qw/name1 name2 name3/] => sub {...});

Create attributes. An arrayref can be used to create more than one attribute. Pass an optional second argument to set a default value, it should be a constant or a sub reference. The sub reference will be excuted at accessor read time if there's no set value.

  • Class::XSAccessor

    Mojo::Base::XS based on Class::XSAccessor with some modifications that imlement Mojo::Base behavior

  • Mojo::Base

Yaroslav Korshak <yko@cpan.org>

Copyright (C) 2011, Yaroslav Korshak

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

2013-05-04 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.