#!/usr/local/bin/perl use strict; use warnings; package Me::Trait::M; use Moose::Role; has mything => ( isa => 'Maybe[Bool]', is => 'rw', default => 0 ); no Moose::Role; package Moose::Meta::Attribute::Custom::Trait::M; sub register_implementation { 'Me::Trait::M'; } package Me; use Moose; has myattr_yes => ( isa => 'Str', is => 'ro', traits => [qw/M/], default => 'this_is_yes', mything => 1, ); has myattr_no => ( isa => 'Str', is => 'ro', default => 'this_is_no', ); sub BUILD { my $self = shift; my $meta = $self->meta; my @attr = $meta->get_all_attributes(); foreach my $at (@attr) { if ($at->does('Me::Trait::M')) { my $closure = $at->name; my $coderef = sub { my $self = shift; print $self->$closure()."\n"; }; $meta->add_method( 'print_' . $closure => $coderef); } } } no Moose; package main; my $f = Me->new(); $f->print_myattr_yes();