package MooseX::AttributeHelpers::String;
use Moose;
+use MooseX::AttributeHelpers::Sugar;
+
+extends 'MooseX::AttributeHelpers::Base';
our $VERSION = '0.01';
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::String;
-
-extends 'MooseX::AttributeHelpers::Base';
+define_attribute_helper (
+ default_options => {
+ is => 'rw',
+ default => '',
+ },
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::String'
+ helper_type => 'Str',
+ method_provider => 'MooseX::AttributeHelpers::MethodProvider::String',
+ auto_provide => 1,
+ shortcut => 'String',
);
-sub helper_type { 'Str' }
-
-before 'process_options_for_provides' => sub {
- my ($self, $options, $name) = @_;
-
- # Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
- $options->{isa} = $type;
- }
-
- $options->{is} = 'rw' unless exists $options->{is};
- $options->{default} = '' unless exists $options->{default};
-};
-
-after 'check_provides_values' => sub {
- my $self = shift;
- my $provides = $self->provides;
-
- unless (scalar keys %$provides) {
- my $method_constructors = $self->method_constructors;
- my $attr_name = $self->name;
-
- foreach my $method (keys %$method_constructors) {
- $provides->{$method} = ($method . '_' . $attr_name);
- }
- }
-};
-
no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::String;
-sub register_implementation { 'MooseX::AttributeHelpers::String' }
+no MooseX::AttributeHelpers::Sugar;
1;
If your attribute definition does not include any of I<is>, I<isa>,
I<default> or I<provides> but does use the C<String> metaclass,
then this module applies defaults as in the L</SYNOPSIS>
-above. This allows for a very basic counter definition:
+above. This allows for a very basic attribute definition:
has 'foo' => (metaclass => 'String');
$obj->append_foo;
=item B<meta>
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=item B<process_options_for_provides>
-
-Run before its superclass method.
-
-=item B<check_provides_values>
-
-Run after its superclass method.
-
=back
=head1 PROVIDED METHODS