Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Cleanups

  • Loading branch information...
commit 8f3add7931810fa6aba05bae6b3f5eb248137327 1 parent 164fbc3
Tomas Doran authored March 29, 2009
75  lib/MooseX/StrictAttributes/AddDefaultAttributeTrait.pm
... ...
@@ -1,75 +0,0 @@
1  
-package MooseX::StrictAttributes::AddDefaultAttributeTrait;
2  
-use Moose::Role;
3  
-use List::MoreUtils qw/any/;
4  
-use namespace::clean -except => [qw/ meta /];
5  
-
6  
-{
7  
-    my @list_of_traits;
8  
-    sub __generate_attribute_trait_appender {
9  
-        my ($self, $trait) = @_;
10  
-        push(@list_of_traits, $trait);
11  
-    }
12  
-
13  
-    around 'add_attribute' => sub {
14  
-        my $orig = shift;
15  
-        my $class = shift;
16  
-        my $attr_name = shift;
17  
-        my $params_hr;
18  
-        if (ref $_[0] eq 'HASH') {
19  
-            $params_hr = shift;
20  
-        }
21  
-        else {
22  
-            $params_hr = { @_ };
23  
-        }
24  
-        $params_hr->{traits} ||= [];
25  
-        foreach my $trait (@list_of_traits) {
26  
-            push(@{ $params_hr->{traits} }, $trait)
27  
-                unless any { $trait eq $_ } 
28  
-                       @{ $params_hr->{traits} };
29  
-        }
30  
-        $orig->($class, $attr_name, %$params_hr);
31  
-    };
32  
-}
33  
-
34  
-1;
35  
-
36  
-__END__
37  
-
38  
-=head1 NAME
39  
-
40  
-MooseX::StrictAttributes::AddDetaultAttributeTrait - A class metaclass role which ensures
41  
-that all attributes added to a metaclass have certain traits.
42  
-
43  
-=head1 SYNOPSIS
44  
-
45  
-    package My::Class
46  
-    use Moose::Role;
47  
-    
48  
-    with 'MooseX::StrictAttributes::AddDetaultAttributeTrait';
49  
-    
50  
-    __PACKAGE__->__generate_attribute_trait_appender('MyTraitName');
51  
-    
52  
-=head1 DESCRIPTION
53  
-
54  
-Uses an around modifier to capture attribute construction, and ensures that the C<traits> option
55  
-passed contains all the values specified.
56  
-
57  
-=head1 BUGS AND SOURCE CODE
58  
-
59  
-The implementation of this component can be considered a bug, as it leaves symbols in the metaclass
60  
-namespace. This code should really be using L<Moose::Exporter> to export declerative sugar, which
61  
-can later be removed.. See the test suite for more information.
62  
-
63  
-Patches welcome. Please ask in #moose for commit bits.
64  
-
65  
-The source code for this project is in the Moose repository at L<http://code2.0beta.co.uk/moose/svn/>
66  
-
67  
-=head1 AUTHORS
68  
-
69  
-Tomas Doran <bobtfish@bobtfish.net> (t0m on #moose)
70  
-
71  
-=head1 COPYRIGHT AND LICENSE
72  
-
73  
-Copyright 2008 Tomas Doran.
74  
-
75  
-This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

0 notes on commit 8f3add7

Please sign in to comment.
Something went wrong with that request. Please try again.