« blib/lib/Class/MakeMethods/Template/ClassName.pm
↑ Summary
blib/lib/Class/MakeMethods/Autoload.pm »
| 1 | package Class::MakeMethods::Template::Array; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use Class::MakeMethods::Template::Generic '-isasubclass'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | $VERSION = 1.008; | |||||||||
| 6 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | require 5.00; | |||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Class::MakeMethods::Template::Array - Methods for manipulating positional values in arrays | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 3 | ▶ | use vars qw( %ClassInfo ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 3 | ▶ | sub generic { | ||||||||
|
Subroutine
generic: called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||
| 24 | { | ||||||||||
| 25 | 'params' => { | ||||||||||
| 26 | 'array_index' => undef, | ||||||||||
| 27 | }, | ||||||||||
| 28 | 'code_expr' => { | ||||||||||
| 29 | _VALUE_ => '_SELF_->[_STATIC_ATTR_{array_index}]', | ||||||||||
| 30 | '-import' => { 'Template::Generic:generic' => '*' }, | ||||||||||
| 31 | _EMPTY_NEW_INSTANCE_ => 'bless [], _SELF_CLASS_', | ||||||||||
| 32 | _SET_VALUES_FROM_HASH_ => 'while ( scalar @_ ) { local $_ = shift(); $self->[ _BFP_FROM_NAME_{ $_ } ] = shift() }' | ||||||||||
| 33 | }, | ||||||||||
| 34 | 'behavior' => { | ||||||||||
| 35 | 15 | ▶ | '-init' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=26.9
| |||||||||||
| 36 | 15 | my $m_info = $_[0]; | |||||||||
| 37 | |||||||||||
| 38 | # If we're the first one, | ||||||||||
| 39 | 15 | ▶ | if ( ! $ClassInfo{$m_info->{target_class}} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | # traverse inheritance hierarchy, looking for fields to inherit | ||||||||||
| 41 | 3 | my @results; | |||||||||
| 42 | 3 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 3 | my @sources = @{"$m_info->{target_class}\::ISA"}; | |||||||||
| 44 | 3 | ▶ | while ( my $class = shift @sources ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | ▶ | next unless exists $ClassInfo{ $class }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | push @sources, @{"$class\::ISA"}; | |||||||||
| 47 | 0 | ▶ | if ( scalar @results ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | Carp::croak "Too many inheritances of fields"; | |||||||||
| 49 | } | ||||||||||
| 50 | 0 | push @results, @{$ClassInfo{$class}}; | |||||||||
| 51 | } | ||||||||||
| 52 | 3 | $ClassInfo{$m_info->{target_class}} = \@sources; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 15 | my $class_info = $ClassInfo{$m_info->{target_class}}; | |||||||||
| 56 | 15 | ▶ | if ( ! defined $m_info->{array_index} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 15 | foreach ( 0..$#$class_info ) { | |||||||||
| 58 | 33 | ▶ | if ( $class_info->[$_] eq $m_info->{'name'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | $m_info->{array_index} = $_; last } | |||||||||
| 60 | } | ||||||||||
| 61 | 15 | ▶ | if ( ! defined $m_info->{array_index} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 15 | push @ $class_info, $m_info->{'name'}; | |||||||||
| 63 | 15 | $m_info->{array_index} = $#$class_info; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 15 | return; | |||||||||
| 68 | }, | ||||||||||
| 69 | }, | ||||||||||
| 70 | } | ||||||||||
| 71 | 3 | } | |||||||||
| 72 | |||||||||||
| 73 | ######################################################################## | ||||||||||
| 74 | |||||||||||
| 75 | =head2 Standard Methods | ||||||||||
| 76 | |||||||||||
| 77 | The following methods from Generic should be supported: | ||||||||||
| 78 | |||||||||||
| 79 | scalar | ||||||||||
| 80 | string | ||||||||||
| 81 | number | ||||||||||
| 82 | boolean | ||||||||||
| 83 | bits (?) | ||||||||||
| 84 | array | ||||||||||
| 85 | hash | ||||||||||
| 86 | tiedhash (?) | ||||||||||
| 87 | hash_of_arrays (?) | ||||||||||
| 88 | object | ||||||||||
| 89 | instance | ||||||||||
| 90 | array_of_objects (?) | ||||||||||
| 91 | code | ||||||||||
| 92 | code_or_scalar (?) | ||||||||||
| 93 | |||||||||||
| 94 | See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types. | ||||||||||
| 95 | |||||||||||
| 96 | The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect. | ||||||||||
| 97 | |||||||||||
| 98 | =cut | ||||||||||
| 99 | |||||||||||
| 100 | ######################################################################## | ||||||||||
| 101 | |||||||||||
| 102 | 3 | 1; | |||||||||