The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

NAME

Object::Botox - simple object constructor with accessor, prototyping and default-settings of inheritanced values.

VERSION

Version 1.15

SYNOPSIS

Object::Botox writed for easy object creation by default constructor and support managment properties, inherited by children of prototyping class.

package Parent;
use Botox; # yes, we now are got |new| constructor
# default properties for ANY object of `Parent` class:
# prop1_ro ISA 'write-protected' && prop2 ISA 'public'
# and seting default value for each other
# strictly named constant PROTOTYPE !
use constant PROTOTYPE => { 'prop1_ro' => 1 , 'prop2' => 'abcde' };

DESCRIPTION

Object::Botox - simple constructor and properties prototyper whith checking of properties existans.

To create parent module:

package Parent;
use Botox;
# strictly named constant PROTOTYPE !
use constant PROTOTYPE => {
'prop1_ro' => 1 ,
'prop2' => 'abcde'
};
sub show_prop1{ # It`s poinlessly - indeed property IS A accessor itself
my ( $self ) = @_;
return $self->prop1;
}
sub set_prop1{ # It`s NEEDED for RO aka protected on write property
my ( $self, $value ) = @_;
$self->prop1($value);
}
sub parent_sub{ # It`s class method itself
my $self = shift;
return $self->prop1;
}
1;

after that we are create instanse:

package main;
# change default value for prop1
my $foo = new Parent( { prop1 => 888888 } );
print Dumper($foo);

outputs get to us:

$VAR1 = bless( {
'Parent::prop1' => 888888,
'Parent::prop2' => 'abcde'
}, 'Parent' );

properties may have _rw[default] or _ro acess mode and inheritated.

eval{ $foo->prop1(-23) };
print $@."\n";

output somthing like this:

Can`t change RO properties |prop1| to |-23| in object Parent from main at ./test_more.t line 84

to deal (write to) with this properties we are must create accessor .

Also all of properties are inheritanced.

package Child;
use base 'Parent';
use constant PROTOTYPE => {
'prop1' => 48,
'prop5' => 55,
'prop8_ro' => 'tetete'
};
1;

give to us something like this

$VAR1 = bless( {
'Child::prop5' => 55,
'Child::prop2' => 'abcde',
'Child::prop1' => 48,
'Child::prop8' => 'tetete'
}, 'Child' );

Chainings - all setter return $self in success, so its chained

$baz->prop1(88)->prop2('loreum ipsum');

EXPORT

new() method by default

SUBROUTINES/METHODS

new

new() - create object (on hashref-base) by prototype and initiate it from args

SEE ALSO

Moose, Mouse, Class::Accessor, Class::XSAccessor

AUTHOR

Meettya, <meettya at cpan.org>

BUGS

Please report any bugs or feature requests to bug-object-botox at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Object-Botox. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Object::Botox

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2011 Meettya.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.