Throw an error if the constructor receives a class attribute.
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute.pm
CommitLineData
4dee0fd3 1package MooseX::ClassAttribute;
2
3use warnings;
4use strict;
5
6our $VERSION = '0.01';
0f24a39d 7our $AUTHORITY = 'cpan:DROLSKY';
8
9use Moose;
10use MooseX::ClassAttribute::Meta::Method::Accessor;
11
12extends 'Moose::Meta::Attribute';
13
a124b299 14
0f24a39d 15sub accessor_metaclass { 'MooseX::ClassAttribute::Meta::Method::Accessor' }
16
17# This is called when an object is constructed.
18sub initialize_instance_slot
19{
a124b299 20 my ( $self, $meta_instance, $instance, $params ) = @_;
21
22 return unless $self->has_init_arg();
23
24 my $init_arg = $self->init_arg();
25
26 confess "Cannot set a class attribute via the constructor ($init_arg)"
27 if exists $params->{$init_arg};
28
0f24a39d 29 return;
30}
31
32
33# This is the bit of magic that lets you specify the metaclass as
a124b299 34# 'ClassAttribute' rather than the full name when creating an
0f24a39d 35# attribute.
36package Moose::Meta::Attribute::Custom::ClassAttribute;
37
38sub register_implementation { 'MooseX::ClassAttribute' }
4dee0fd3 39
40
411;
42
43__END__
44
45=pod
46
47=head1 NAME
48
49MooseX::ClassAttribute - The fantastic new MooseX::ClassAttribute!
50
4dee0fd3 51=head1 SYNOPSIS
52
53Quick summary of what the module does.
54
55Perhaps a little code snippet.
56
57 use MooseX::ClassAttribute;
58
0f24a39d 59 my $foo = MooseX::ClassAttribute->new();
4dee0fd3 60
61 ...
62
63=head1 METHODS
64
65This class provides the following methods
66
67=head1 AUTHOR
68
69Dave Rolsky, C<< <autarch@urth.org> >>
70
71=head1 BUGS
72
73Please report any bugs or feature requests to C<bug-moosex-classattribute@rt.cpan.org>,
74or through the web interface at L<http://rt.cpan.org>. I will be
75notified, and then you'll automatically be notified of progress on
76your bug as I make changes.
77
78=head1 COPYRIGHT & LICENSE
79
80Copyright 2007 Dave Rolsky, All Rights Reserved.
81
82This program is free software; you can redistribute it and/or modify
83it under the same terms as Perl itself.
84
85=cut