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'} }
43 sub add_package_symbol {
44 my ($self, $variable, $initial_value) = @_;
47 || confess "You must pass a variable name";
49 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
52 || confess "The variable name must include a sigil";
54 (exists $SIGIL_MAP{$sigil})
55 || confess "I do not recognize that sigil '$sigil'";
59 *{$self->name . '::' . $name} = $initial_value;
62 sub has_package_symbol {
63 my ($self, $variable) = @_;
65 || confess "You must pass a variable name";
67 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
70 || confess "The variable name must include a sigil";
72 (exists $SIGIL_MAP{$sigil})
73 || confess "I do not recognize that sigil '$sigil'";
76 defined *{$self->name . '::' . $name}{$SIGIL_MAP{$sigil}} ? 1 : 0;
80 sub get_package_symbol {
81 my ($self, $variable) = @_;
83 || confess "You must pass a variable name";
85 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
88 || confess "The variable name must include a sigil";
90 (exists $SIGIL_MAP{$sigil})
91 || confess "I do not recognize that sigil '$sigil'";
94 return *{$self->name . '::' . $name}{$SIGIL_MAP{$sigil}};
98 sub remove_package_symbol {
99 my ($self, $variable) = @_;
102 || confess "You must pass a variable name";
104 my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
107 || confess "The variable name must include a sigil";
109 (exists $SIGIL_MAP{$sigil})
110 || confess "I do not recognize that sigil '$sigil'";
113 if ($SIGIL_MAP{$sigil} eq 'SCALAR') {
114 undef ${$self->name . '::' . $name};
116 elsif ($SIGIL_MAP{$sigil} eq 'ARRAY') {
117 undef @{$self->name . '::' . $name};
119 elsif ($SIGIL_MAP{$sigil} eq 'HASH') {
120 undef %{$self->name . '::' . $name};
122 elsif ($SIGIL_MAP{$sigil} eq 'CODE') {
123 undef &{$self->name . '::' . $name};
126 confess "This should never ever ever happen";
138 Class::MOP::Package - Package Meta Object
154 =item B<add_package_symbol>
156 =item B<get_package_symbol>
158 =item B<has_package_symbol>
160 =item B<remove_package_symbol>
166 Stevan Little E<lt>stevan@iinteractive.comE<gt>
168 =head1 COPYRIGHT AND LICENSE
170 Copyright 2006 by Infinity Interactive, Inc.
172 L<http://www.iinteractive.com>
174 This library is free software; you can redistribute it and/or modify
175 it under the same terms as Perl itself.