EO::NotAttributes - alternatives to attributes used by EO


EO documentation Contained in the EO distribution.

Index


Code Index:

NAME

Top

EO::NotAttributes - alternatives to attributes used by EO

SYNOPSIS

Top

  use EO::NotAttributes;

  sub::Abstract 'bar';

DESCRIPTION

Top

Attributes are nice, but they can't be used in all situations. At the time of writing, perl (5.8.3) cannot apply attributes to code that is loaded at run time.

This module provides an alternative interface instead of using attributes; A declarative syntax that can be used to perform similar actions to thier EO::Attribute counterparts.

AUTHOR

Top

Mark Fowler <mark@twoshortplanks.com>

SEE ALSO

Top

EO, EO::Attributes

COPYRIGHT

Top

BUGS

Top

There's no implementation of 'Private' yet. This isn't a problem yet ;-).


EO documentation Contained in the EO distribution.
package EO::NotAttributes;

# this isn't an EO object, but it needs the EO::Error::* stuff
# declared in there.
use EO;

use strict;
use warnings;

use Scalar::Util qw(blessed);

our $VERSION = 0.96;

sub sub::Abstract($) {
  my $meth = shift;
  my ($package, $filename, $line) = caller;
  no strict 'refs';
  no warnings 'redefine';
  *{"${package}::${meth}"} = sub {
    my $self = shift;
    my $class = blessed($self) ? ref($self) : $self;
    my ($package, $filename, $line) = caller();
    my $text = "Can't call abstract method \"$meth\" on object of type \"$class\"";
    throw EO::Error::Method::Abstract
      text => $text,
      file => $filename;
  };
}

sub sub::abstract($) { sub::Abstract(@_) }

1;

__END__