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:
new
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.
attr
__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.
To install Mojo::Base::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Base::XS
CPAN shell
perl -MCPAN -e shell install Mojo::Base::XS
For more information on module installation, please visit the detailed CPAN module installation guide.