Commit | Line | Data |
190b1c02 |
1 | package MooseX::AttributeHelpers::String; |
2 | use Moose; |
786dbc3d |
3 | use MooseX::AttributeHelpers::MethodProvider::String; |
8683383a |
4 | |
5 | extends 'MooseX::AttributeHelpers::Base'; |
190b1c02 |
6 | |
7 | our $VERSION = '0.01'; |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | |
786dbc3d |
10 | __PACKAGE__->sugar( |
8683383a |
11 | default_options => { |
12 | is => 'rw', |
13 | default => '', |
14 | }, |
190b1c02 |
15 | |
8683383a |
16 | auto_provide => 1, |
786dbc3d |
17 | method_provider => 'String', |
8683383a |
18 | shortcut => 'String', |
190b1c02 |
19 | ); |
20 | |
190b1c02 |
21 | no Moose; |
190b1c02 |
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> |
8683383a |
63 | above. This allows for a very basic attribute definition: |
190b1c02 |
64 | |
65 | has 'foo' => (metaclass => 'String'); |
66 | $obj->append_foo; |
67 | |
190b1c02 |
68 | =head1 PROVIDED METHODS |
69 | |
720fa35b |
70 | The methods for this metaclass are provided by |
71 | L<MooseX::AttributeHelpers::MethodProvider::String>. |
190b1c02 |
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 | |
99c62fb8 |
85 | Copyright 2007-2008 by Infinity Interactive, Inc. |
190b1c02 |
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 |