Lines 130-173
sub AUTOLOAD {
Link Here
|
130 |
my $self = shift(@args); |
130 |
my $self = shift(@args); |
131 |
my $name = $AUTOLOAD; |
131 |
my $name = $AUTOLOAD; |
132 |
$name =~ s/.*:://; # Remove package name |
132 |
$name =~ s/.*:://; # Remove package name |
133 |
my $found = 0; |
133 |
|
134 |
|
134 |
return try { |
135 |
# Fetch attributes dynamically |
135 |
my $wt = 'SUPER::' . $name; |
136 |
my $attribute_types = Koha::Patron::Attribute::Types->search(); |
136 |
$self->$wt(@args); |
137 |
while ( my $attr = $attribute_types->next ) { |
137 |
} catch { |
138 |
my $code = $attr->code; |
138 |
|
139 |
$found = 1 if ( $code eq $name ); |
139 |
# Fetch attributes dynamically |
140 |
|
140 |
my $found = 0; |
141 |
# Dynamically create accessor method |
141 |
my $attribute_types = Koha::Patron::Attribute::Types->search(); |
142 |
no strict 'refs'; |
142 |
while ( my $attr = $attribute_types->next ) { |
143 |
if ( !defined *{ ref($self) . "::$code" }{CODE} ) { |
143 |
my $code = $attr->code; |
144 |
if ( $attr->repeatable ) { |
144 |
$found = 1 if ( $code eq $name ); |
145 |
*{ ref($self) . "::$code" } = sub { |
145 |
|
146 |
my ($self) = @_; |
146 |
# Dynamically create accessor method |
147 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
147 |
no strict 'refs'; |
148 |
my $attributes = $self->_result->borrower_attributes->search( { code => $code } ); |
148 |
if ( !defined *{ ref($self) . "::$code" }{CODE} ) { |
149 |
my $values = []; |
149 |
if ( $attr->repeatable ) { |
150 |
while ( my $attribute = $attributes->next ) { |
150 |
*{ ref($self) . "::$code" } = sub { |
151 |
push @$values, $attribute->attribute; |
151 |
my ($self) = @_; |
152 |
} |
152 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
153 |
return $values; |
153 |
my $attributes = $self->_result->borrower_attributes->search( { code => $code } ); |
154 |
}; |
154 |
my $values = []; |
155 |
} else { |
155 |
while ( my $attribute = $attributes->next ) { |
156 |
*{ ref($self) . "::$code" } = sub { |
156 |
push @$values, $attribute->attribute; |
157 |
my ($self) = @_; |
157 |
} |
158 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
158 |
return $values; |
159 |
my $attribute = $self->_result->borrower_attributes->search( { code => $code } )->first; |
159 |
}; |
160 |
return $attribute ? $attribute->attribute : undef; |
160 |
} else { |
161 |
}; |
161 |
*{ ref($self) . "::$code" } = sub { |
|
|
162 |
my ($self) = @_; |
163 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
164 |
my $attribute = $self->_result->borrower_attributes->search( { code => $code } )->first; |
165 |
return $attribute ? $attribute->attribute : undef; |
166 |
}; |
167 |
} |
162 |
} |
168 |
} |
163 |
} |
169 |
} |
164 |
} |
|
|
165 |
|
170 |
|
166 |
if ($found) { |
171 |
if ($found) { |
167 |
return $self->$name(); |
172 |
return $self->$name(); |
168 |
} else { |
173 |
} else { |
169 |
my $wt = 'SUPER::' . $name; |
174 |
$@; |
170 |
return $self->$wt(@args); |
175 |
} |
171 |
} |
176 |
} |
172 |
} |
177 |
} |
173 |
|
178 |
|
174 |
- |
|
|