Skip to content

Instantly share code, notes, and snippets.

@anazawa
Created February 4, 2012 04:51
Show Gist options
  • Select an option

  • Save anazawa/1735425 to your computer and use it in GitHub Desktop.

Select an option

Save anazawa/1735425 to your computer and use it in GitHub Desktop.
make accessors
for my $field (qw(type nph expires cookie charset attachment p3p)) {
my $slot = __PACKAGE__."::$field";
my $code = sub {
my $self = shift;
my $value = shift;
if ($value) {
$self->set($field => $value);
}
else {
my @values = $self->get($field);
wantarray ? @values : $values[0];
}
};
no strict 'refs';
*$slot = $code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment