2 package Class::MOP::Package;
7 use Scalar::Util 'blessed';
10 our $VERSION = '0.01';
15 require Class::MOP::Class;
16 Class::MOP::Class->initialize(blessed($_[0]) || $_[0]);
22 my ($class, $package) = @_;
23 bless { '$:package' => $package } => $class;
29 # all these attribute readers will be bootstrapped
30 # away in the Class::MOP bootstrap section
32 sub name { $_[0]->{'$:package'} }
44 sub add_package_symbol {
45 my ($self, $variable, $initial_value) = @_;
48 || confess "You must pass a variable name";
50 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
53 || confess "The variable name must include a sigil";
55 (exists $SIGIL_MAP{$sigil})
56 || confess "I do not recognize that sigil '$sigil'";
60 *{$self->name . '::' . $name} = $initial_value;
63 sub has_package_symbol {
64 my ($self, $variable) = @_;
66 || confess "You must pass a variable name";
68 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
71 || confess "The variable name must include a sigil";
73 (exists $SIGIL_MAP{$sigil})
74 || confess "I do not recognize that sigil '$sigil'";
77 defined *{$self->name . '::' . $name}{$SIGIL_MAP{$sigil}} ? 1 : 0;
81 sub get_package_symbol {
82 my ($self, $variable) = @_;
84 || confess "You must pass a variable name";
86 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
89 || confess "The variable name must include a sigil";
91 (exists $SIGIL_MAP{$sigil})
92 || confess "I do not recognize that sigil '$sigil'";
95 return *{$self->name . '::' . $name}{$SIGIL_MAP{$sigil}};
99 sub remove_package_symbol {
100 my ($self, $variable) = @_;
103 || confess "You must pass a variable name";
105 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
108 || confess "The variable name must include a sigil";
110 (exists $SIGIL_MAP{$sigil})
111 || confess "I do not recognize that sigil '$sigil'";
114 if ($SIGIL_MAP{$sigil} eq 'SCALAR') {
115 undef ${$self->name . '::' . $name};
117 elsif ($SIGIL_MAP{$sigil} eq 'ARRAY') {
118 undef @{$self->name . '::' . $name};
120 elsif ($SIGIL_MAP{$sigil} eq 'HASH') {
121 undef %{$self->name . '::' . $name};
123 elsif ($SIGIL_MAP{$sigil} eq 'CODE') {
124 undef &{$self->name . '::' . $name};
127 confess "This should never ever ever happen";
141 Class::MOP::Package - Package Meta Object
157 =item B<add_package_symbol>
159 =item B<get_package_symbol>
161 =item B<has_package_symbol>
163 =item B<remove_package_symbol>
169 Stevan Little E<lt>stevan@iinteractive.comE<gt>
171 =head1 COPYRIGHT AND LICENSE
173 Copyright 2006 by Infinity Interactive, Inc.
175 L<http://www.iinteractive.com>
177 This library is free software; you can redistribute it and/or modify
178 it under the same terms as Perl itself.