| 1 | package Chart::Sequence::Object; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | $VERSION = 0.000_1; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Chart::Sequence::Object - A base class with utility functions for all Chart::Sequence objects | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =for test_script t/Chart-Sequence.t | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =over | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =item new | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | use vars qw( %_initted_members ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=31.3
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | if ( @_ == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( ref $_[0] eq "HASH" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | @_ = %{$_[0]}; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 41 | 1 | local %_initted_members; | |||||||||||||||||||||||||||
| 42 | 1 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | my ( $key, $value ) = ( shift, shift ); | |||||||||||||||||||||||||||
| 44 | 0 | ( my $method_name = $key ) =~ s/^([A-Z])/\l$1/; | |||||||||||||||||||||||||||
| 45 | 0 | $method_name =~ s/([A-Z])/_\l$1/g; | |||||||||||||||||||||||||||
| 46 | 0 | my $method = $self->can( "_init_$method_name" ); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ( $method ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $method_name = "_init_$method_name"; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||
| 51 | 0 | $method = $self->can( $method_name ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | croak "Can't find method '$method_name' in $class" unless $method; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | $self->$method( $value ); | |||||||||||||||||||||||||||
| 55 | 0 | $_initted_members{ $method_name }++; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 1 | $self->_init_members( ref $self ); | |||||||||||||||||||||||||||
| 58 | 1 | return $self; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 7 | __PACKAGE__->make_methods(qw( $name )); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub _init_members { | ||||||||||||||||||||||||||
|
Subroutine
_init_members: called CC=5 SCAR=20.3
| |||||||||||||||||||||||||||||
| 65 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 1 | my ( $class ) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 7 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 1 | for ( @{"${class}::ISA"} ) { | |||||||||||||||||||||||||||
| 70 | 0 | my $s = $_->can( "_init_members" ); | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->$s( $_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | if $s; | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | for ( @{"${class}::_member_initers"} ) { | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | next if $_initted_members{$_}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | $self->$_(); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item name | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Sets/gets the name of an object. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =cut | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =item make_methods | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Builds accessor methods for the indicated data elements: | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | __PACKAGE__->make_methods( qw( | ||||||||||||||||||||||||||||
| 92 | $name | ||||||||||||||||||||||||||||
| 93 | @messages | ||||||||||||||||||||||||||||
| 94 | ) ); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 13 | ▶ | sub make_methods { | ||||||||||||||||||||||||||
|
Subroutine
make_methods: called CC=10 SCAR=23.6
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 13 | my $class = shift; | |||||||||||||||||||||||||||
| 100 | 13 | my @code; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 13 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 19 | local $_ = shift; | |||||||||||||||||||||||||||
| 104 | 19 | ▶ | my $options = @_ && ref $_[0] ? shift : {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0]
MC/DC0%0/2
@_ and ref $_[0]
@_
ref $_[0]
Truth table66%2/3
A and B
A= @_B= ref $_[0]
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 19 | s/^([\$\@])//; | |||||||||||||||||||||||||||
| 107 | 19 | ▶ | my $type = $1 || "\$"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$1 || '$'
MC/DC100%1/1
$1 || '$'
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||
| 108 | 19 | ( my $n = $_ ) =~ s{(?:^|_)(\w)}{\u$1}g; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 19 | ▶ | my $set_pre = defined $options->{set_pre} ? $options->{set_pre} : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 19 | ▶ | my $get_pre = defined $options->{get_pre} ? $options->{get_pre} : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 19 | push @code, <<END_MAP; | |||||||||||||||||||||||||||
| 114 | \$${class}::_member_types{$_} = '$type'; | ||||||||||||||||||||||||||||
| 115 | END_MAP | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 19 | ▶ | if ( $type eq "\$" ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 118 | 13 | push @code, <<END_SUB; | |||||||||||||||||||||||||||
| 119 | #line 1 ${class}::$_, compiled by Class::Sequence::Base::make_methods | ||||||||||||||||||||||||||||
| 120 | sub $_ { | ||||||||||||||||||||||||||||
| 121 | my \$self = shift; | ||||||||||||||||||||||||||||
| 122 | Carp::croak "Too many parameters passed" if \@_ > 1; | ||||||||||||||||||||||||||||
| 123 | if ( \@_ ) { | ||||||||||||||||||||||||||||
| 124 | local \$_ = shift; | ||||||||||||||||||||||||||||
| 125 | $set_pre | ||||||||||||||||||||||||||||
| 126 | \$self->{$n} = \$_; | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | $get_pre | ||||||||||||||||||||||||||||
| 129 | return \$self->{$n}; | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | END_SUB | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | elsif ( $type eq "\@" ) { | ||||||||||||||||||||||||||||
| 134 | 0 | push @code, <<END_SUB; | |||||||||||||||||||||||||||
| 135 | #line 1 ${class}::_init_$_, compiled by Class::Sequence::Base::make_methods | ||||||||||||||||||||||||||||
| 136 | sub _init_$_ { | ||||||||||||||||||||||||||||
| 137 | my \$self = shift; | ||||||||||||||||||||||||||||
| 138 | \$self->{$n} = []; | ||||||||||||||||||||||||||||
| 139 | map \$self->push_$_( \$_ ), \@{shift()} if \@_; | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | push \@${class}::_member_initers, "_init_$_"; | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | #line 1 ${class}::$_, compiled by Class::Sequence::Base::make_methods | ||||||||||||||||||||||||||||
| 144 | sub $_ { | ||||||||||||||||||||||||||||
| 145 | my \$self = shift; | ||||||||||||||||||||||||||||
| 146 | if ( \@_ ) { | ||||||||||||||||||||||||||||
| 147 | \$self->_init_$_; | ||||||||||||||||||||||||||||
| 148 | \$self->push_$_( \@_ ); | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | $get_pre | ||||||||||||||||||||||||||||
| 151 | return \@{\$self->{$n}}; | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | #line 1 ${class}::${_}_ref, compiled by Class::Sequence::Base::make_methods | ||||||||||||||||||||||||||||
| 155 | sub ${_}_ref { | ||||||||||||||||||||||||||||
| 156 | my \$self = shift; | ||||||||||||||||||||||||||||
| 157 | Carp::croak "Too many parameters passed" if \@_ > 1; | ||||||||||||||||||||||||||||
| 158 | if ( \@_ ) { | ||||||||||||||||||||||||||||
| 159 | \$self->_init_$_; | ||||||||||||||||||||||||||||
| 160 | \$self->push_$_( \@{\$_[1]} ); | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | $get_pre | ||||||||||||||||||||||||||||
| 163 | return \$self->{$n}; | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | #line 1 ${class}::push_$_, compiled by Class::Sequence::Base::make_methods | ||||||||||||||||||||||||||||
| 167 | sub push_$_ { | ||||||||||||||||||||||||||||
| 168 | my \$self = shift; | ||||||||||||||||||||||||||||
| 169 | while ( \@_ ) { | ||||||||||||||||||||||||||||
| 170 | local \$_ = shift; | ||||||||||||||||||||||||||||
| 171 | $set_pre | ||||||||||||||||||||||||||||
| 172 | push \@{\$self->{$n}}, \$_; | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | END_SUB | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||
| 178 | 6 | croak "Unrecognized accessor type: '$type'"; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 7 | ▶ | eval join "", "package ", $class, ";\n", @code, 1 or die $@, @code; | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=3 SCAR=11.1
Pod
documented
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =back | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Copyright 2002, R. Barrie Slaymaker, Jr., All Rights Reserved | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | You may use this module under the terms of the BSD, Artistic, oir GPL licenses, | ||||||||||||||||||||||||||||
| 195 | any version. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | Barrie Slaymaker <barries@slaysys.com> | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 7 | 1; | |||||||||||||||||||||||||||