The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Attribute::Method - No more 'my $self = shift;'

SYNOPSIS

  package Lazy;
  use strict;
  use warnings;
  use Attribute::Method qw( $val );
                        # pass all parameter names here
                        # to make strict.pm happy
  sub new : Method { 
      bless { @_ }, $self 
  }
  sub set_foo : Method( $val ){
      $self->{foo} = $val;
  }
  sub get_foo : Method {
      $self->{val};
  }
  #....

DESCRIPTION

This Attribute makes your subroutine a method -- $self is automagically set and the parameter list is supported.

This trick is actually introduced in "Perl Hacks", hack #47. But the code sample therein is a little buggy so have a look at this module instead.

BUGS

None known so far. If you find any bugs or oddities, please do inform the author.

AUTHOR

Dan Kogai, <dankogai@dan.co.jp>

COPYRIGHT

Copyright 2008 Dan Kogai. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1), Attribute::Handlers

Perl Hacks, isbn:0596526741