EO::Method - a class that represents methods


EO documentation Contained in the EO distribution.

Index


Code Index:

NAME

Top

EO::Method - a class that represents methods

SYNOPSIS

Top

  use EO::Method;

  $method = EO::Method->new();

  $method->name( 'foo' );
  my $name = $method->name;

  $method->reference( sub {} );
  my $ref = $method->reference;

  my $results = $method->call( @args );

  $method->new_with_reference( 'foo' => sub {} );

DESCRIPTION

Top

EO::Method provides a representation of methods in a system. In general objects of this class will be created by instances of EO::Class.

INHERITANCE

Top

EO::Method inherits from the EO class.

CONSTRUCTOR

Top

new_with_reference( NAME => CODEREF )

Returns an EO::Method object that has the name NAME and the reference CODEREF

METHODS

Top

name( [STRING] )

Gets and sets the methods name

reference( [CODEREF] )

Gets and sets the code that the method uses

call( LIST )

Calls the references with the arguments specified by LIST.

SEE ALSO

Top

EO::Class

AUTHOR

Top

James A. Duncan <jduncan@fotango.com>

COPYRIGHT

Top


EO documentation Contained in the EO distribution.

package EO::Method;

use strict;
use warnings;

use EO;
our @ISA = qw( EO );
our $VERSION = 0.96;

sub new_with_reference {
  my $class = shift;
  my $name = shift;
  my $ref  = shift;
  my $self = $class->new( @_ );
  $self->name( $name );
  $self->reference( $ref );
  return $self;
}

sub name {
  my $self = shift;
  if (@_) {
    $self->{ methodname } = shift;
    return $self;
  }
  return $self->{ methodname };
}

sub reference {
  my $self = shift;
  if (@_) {
    $self->{ methodreference } = shift;
    return $self;
  }
  return $self->{ methodreference };
}

sub code {
  my $self = shift;
  my $class = EO::Class->new_with_classname( 'B::Deparse' );
  eval {
    $class->load;
  };
  if (!$@) {
    my $b = B::Deparse->new();
    return $b->coderef2text( $self->reference );
  }
}

sub call {
  my $self = shift;
  $self->reference->( @_ );
}

1;

__END__