Objects::Collection::Base - abstract class.


Objects-Collection documentation Contained in the Objects-Collection distribution.

Index


Code Index:

NAME

Top

 Objects::Collection::Base - abstract class.

SYNOPSIS

Top

    use Objects::Collection::Base;
    @Objects::Collection::ISA = qw(Objects::Collection::Base);

DESCRIPTION

Top

Abstract class.

METHODS

Top

SEE ALSO

Top

Objects::Collection, README

AUTHOR

Top

Zahatski Aliaksandr, <zag@cpan.org>

COPYRIGHT AND LICENSE

Top


Objects-Collection documentation Contained in the Objects-Collection distribution.
package Objects::Collection::Base;

#$Id: Base.pm,v 1.3 2006/04/27 14:56:19 zag Exp $


use strict;
use warnings;
use strict;
use Carp;
use Data::Dumper;
require Exporter;
@Objects::Collection::Base::ISA    = qw(Exporter);
@Objects::Collection::Base::EXPORT = qw(attributes);
$Objects::Collection::Base::VERSION = '0.01';

sub attributes {
    my ($pkg) = caller;
    no strict;
    croak "Error: attributes() invoked multiple times"
      if scalar @{"${pkg}::__ATTRIBUTES__"};

    @{"${pkg}::__ATTRIBUTES__"} = @_;
    my $code = "";
    foreach my $attr (@_) {
        if ( UNIVERSAL::can( $pkg, "$attr" ) ) {
            next;
        }
        $code .= _define_accessor( $pkg, $attr );
    }
    eval $code;
}

sub _define_accessor {
    my ( $pkg, $attr ) = @_;
    my $code = qq{
        package $pkg;
        sub $attr {                                      # Accessor ...
            my \$self=shift;
            \@_ ? \$self->{ Var }->{ $attr } = shift : \$self->{ Var }->{ $attr };
        }
    };
    $code;
}

sub new {
    my $class = shift;
    my $self  = {};
    my $stat;
    bless( $self, $class );
    return ( $stat = $self->_init(@_) ) ? $self : $stat;
}

sub _init {
    my $self = shift;
    return 1;
}


# Preloaded methods go here.

1;
__END__