All unit tests passing with refactored stuff, documentation updated significantly.
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / String.pm
1
2 package MooseX::AttributeHelpers::String;
3 use Moose;
4 use MooseX::AttributeHelpers::Sugar;
5
6 extends 'MooseX::AttributeHelpers::Base';
7
8 our $VERSION   = '0.01';
9 our $AUTHORITY = 'cpan:STEVAN';
10
11 define_attribute_helper (
12     default_options  => {
13         is      => 'rw',
14         default => '',
15     },
16
17     helper_type      => 'Str',
18     method_provider  => 'MooseX::AttributeHelpers::MethodProvider::String',
19     auto_provide     => 1,
20     shortcut         => 'String',
21 );
22
23 no Moose;
24 no MooseX::AttributeHelpers::Sugar;
25
26 1;
27
28 __END__
29
30 =pod
31
32 =head1 NAME
33
34 MooseX::AttributeHelpers::String
35
36 =head1 SYNOPSIS
37
38   package MyHomePage;
39   use Moose;
40   use MooseX::AttributeHelpers;
41   
42   has 'text' => (
43       metaclass => 'String',
44       is        => 'rw',
45       isa       => 'Str',
46       default   => sub { '' },
47       provides  => {
48           append => "add_text",
49           replace => "replace_text",
50       }
51   );
52
53   my $page = MyHomePage->new();
54   $page->add_text("foo"); # same as $page->text($page->text . "foo");
55   
56 =head1 DESCRIPTION
57
58 This module provides a simple string attribute, to which mutating string
59 operations can be applied more easily (no need to make an lvalue attribute
60 metaclass or use temporary variables). Additional methods are provided for
61 completion.
62
63 If your attribute definition does not include any of I<is>, I<isa>,
64 I<default> or I<provides> but does use the C<String> metaclass,
65 then this module applies defaults as in the L</SYNOPSIS>
66 above. This allows for a very basic attribute definition:
67
68   has 'foo' => (metaclass => 'String');
69   $obj->append_foo;
70
71 =head1 PROVIDED METHODS
72
73 The methods for this metaclass are provided by
74 L<MooseX::AttributeHelpers::MethodProvider::String>.
75
76 =head1 BUGS
77
78 All complex software has bugs lurking in it, and this module is no 
79 exception. If you find a bug please either email me, or add the bug
80 to cpan-RT.
81
82 =head1 AUTHOR
83
84 Stevan Little E<lt>stevan@iinteractive.comE<gt>
85
86 =head1 COPYRIGHT AND LICENSE
87
88 Copyright 2007-2008 by Infinity Interactive, Inc.
89
90 L<http://www.iinteractive.com>
91
92 This library is free software; you can redistribute it and/or modify
93 it under the same terms as Perl itself.
94
95 =cut