Class-MethodMaker
view release on metacpan or search on metacpan
components/scalar.m view on Meta::CPAN
unless ! ref $type;
# forward option
my $forward = $options->{forward};
my @forward;
if ( defined $forward ) {
if ( ref $forward ) {
croak("-forward option can only handle arrayrefs or simple values " .
"($forward)\n")
unless UNIVERSAL::isa($forward, 'ARRAY');
@forward = @$forward;
print "Value '$_' passed to -forward is not a simple value"
for grep ref($_), @forward;
} else {
@forward = $forward;
}
}
# default options
my ($default, $dctor, $default_defined, $v1object);
if ( exists $options->{default} ) {
croak("Cannot specify both default & default_ctor options to scalar ",
"(attribute $name\n")
if exists $options->{default_ctor};
$default = $options->{default};
$default_defined = 1;
} elsif ( exists $options->{default_ctor} ) {
if ( ! ref $options->{default_ctor} ) {
my $meth = $options->{default_ctor};
croak("default_ctor can only be a simple value when -type is in effect",
" (attribute $name)\n")
unless defined $type;
croak("default_ctor must be a valid identifier (or a code ref): $meth ",
"(attribute $name)\n")
unless $meth =~ /^[A-Za-z_][A-Za-z0-9_]*/;
$dctor = sub { $type->$meth(@_) };
$v1object = $options->{v1_object}
if $options->{v1_compat};
} else {
$dctor = $options->{default_ctor};
croak(sprintf( "Argument to default_ctor must be a simple value or a code ref " .
" (attribute $name) (got '%s')\n", ref $dctor ) )
if ! UNIVERSAL::isa($dctor, 'CODE');
}
$default_defined = 1;
}
# tie options
my ($tie_class, @tie_args);
if ( exists $options->{tie_class} ) {
$tie_class = $options->{tie_class};
if ( exists $options->{tie_args} ) {
my $tie_args = $options->{tie_args};
@tie_args = ref $tie_args ? @$tie_args : $tie_args;
}
} elsif ( exists $options->{tie_args} ) {
carp "tie_args option ignored in absence of tie_class(attribute $name)\n";
}
# callback options
my @read_callbacks = ref $options->{read_cb} eq 'ARRAY' ?
@{$options->{read_cb}} :
$options->{read_cb}
if exists $options->{read_cb};
my @store_callbacks = ref $options->{store_cb} eq 'ARRAY' ?
@{$options->{store_cb}} :
$options->{store_cb}
if exists $options->{store_cb};
# V1 Compatibility
my ($list, $key_create);
($list, $key_create) = @{$options}{qw/ _value_list key_create/}
if exists $options->{_value_list};
# the method definitions ------------
%%STORDECL%%
# Predefine keys for subs we always want to exist (because they're
# referenced by other subs)
my %names = map {; $_ => undef } qw( * );
=pod
Methods available are:
=cut
my %methods =
=pod
=head3 C<*>
$m->a(3);
$a = $m->a; # 3
$a = $m->a(5); # 5;
I<Created by default>. If an argument is provided, the component is set to
that value. The method returns the value of the component (after assignment
to a provided value, if appropriate).
=cut
( '*' => sub : method {
my $z = \@_; # work around stack problems
if ( @_ == 1 ) {
%%V1COMPAT_ON%%
if ( $v1object and ! exists $_[0]->{$name} ) {
%%STORAGE%% = $dctor->();
}
%%V1COMPAT_OFF%%
%%DEFCHECK$%%
%%READ0(%%STORAGE%%)%%
} else {
%%STORE($_[1],$v)%% %%V2ONLY%%
%%V1COMPAT_ON%%
%%STORE($_[1],$v,@_[1..$#_])%%
unless ( $v1object ) {
%%ASGNCHK$(%%IFSTORE($v,$_[1])%%)%%
}
%%V1COMPAT_OFF%%
%%ASGNCHK$(%%IFSTORE($v,$_[1])%%)%% %%V2ONLY%%
%%STORAGE%% = %%IFSTORE($v,$_[1])%%; %%V2ONLY%%
%%V1COMPAT_ON%%
if ( $v1object ) {
( run in 0.497 second using v1.01-cache-2.11-cpan-140bd7fdf52 )