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