On Jun 17, 2010, at 7:54 PM, Kate Yoak wrote:
I would be interested to see an example of how you would use augment and inner with roles. I could never picture a way to do it in which it didn't seem overly confusing, but I am always willing to admit to my own lack of imagination :)

- Stevan



Cool! I like imaginative. I'll start with what I am actually doing - a fancy package installer.

package Installer::Role;

sub prepare{
  my $self = shift;
  $self->find_right_version;
  $self->make_other_common_things;
  inner;
  $self->signal_other_parts_of_the_system_and_stuff;
}

package Installer::WTF_OMG; #I just thought that was so funny yesterday!

augment prepare => sub {
   my $self = shift;
   $self->make_configuration_file;
};

package Installer::LittleApp;

augment prepare => sub{
    my $self = shift;
    $self->load_this_weird_db_the_little_app_is_using;
};


The problem with the above is that Installer::WTF_OMG and Installer::LittleApp would need to have Installer::Role applied to their /superclass/ in order for this to work. You cannot augment a local method, it requires inheritance to be in the mix. Only method modifiers like before, after and around can act on locally defined methods like that.

What you are doing here makes more sense doing something like CUSTOM_PREPARE as you suggest, or to not use roles and make Installer::Role into Installer::Base instead. I would likely lean towards ditching roles since this type of situation is *exactly* the type of situation where augment/inner are the most useful.

- Stevan






Reply via email to