moritz' answer is perfectly good. Here's another in the spirit of TIMTOWTDI. It uses builders instead of defaults. (Slightly slower object construction, but generally considered a cleaner way of doing things in terms of making it easier for subclassing.)
my @ldap_attrs = qw(
ssl host port retry timeout version
loginID loginPW logging
);
use constant {
_build_ssl => 1,
_build_port => 12345,
_build_timeout => 42,
};
has $_ => (
is => "rw",
reader => "get_$_",
writer => "set_$_",
required => 0,
__PACKAGE__->can("_build_$_")
? (builder => "_build_$_")
: (),
) for @ldap_attrs;
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name