NAME
Mojo::Base::XS - very fast Mojo-styled accessors
SYNOPSIS
# 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
DESCRIPTION
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.
EXPORTS
Mojo::Base::XS exports following functions:
has
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.
FUNCTIONS
Mojo::Base::XS implements following functions:
newxs_attr
newxs_attr(
'Class'
,
'attr'
);
Class->attr(
foo
=>
'bar'
);
Class->foo;
# bar
Installs XS attribute generator subroutine
newxs_constructor
newxs_attr(
'Class'
,
'new'
);
Class->new(
foo
=>
'bar'
);
Class->{foo};
# bar
Installs XS constructor
accessor, accessor_init, constructor, constructor_init
Inherited from Class::XSAccessors for internal use
METHODS
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.
SEE ALSO
-
Mojo::Base::XS based on Class::XSAccessor with some modifications that imlement Mojo::Base behavior
AUTHOR
Yaroslav Korshak <yko@cpan.org>
LICENCE AND COPYRIGHT
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.