|
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 |
my $error = $_; |
| 139 |
$found = 1 if ( $code eq $name ); |
139 |
|
| 140 |
|
140 |
# Fetch attributes dynamically |
| 141 |
# Dynamically create accessor method |
141 |
my $found = 0; |
| 142 |
no strict 'refs'; |
142 |
my $attribute_types = Koha::Patron::Attribute::Types->search(); |
| 143 |
if ( !defined *{ ref($self) . "::$code" }{CODE} ) { |
143 |
while ( my $attr = $attribute_types->next ) { |
| 144 |
if ( $attr->repeatable ) { |
144 |
my $code = $attr->code; |
| 145 |
*{ ref($self) . "::$code" } = sub { |
145 |
$found = 1 if ( $code eq $name ); |
| 146 |
my ($self) = @_; |
146 |
|
| 147 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
147 |
# Dynamically create accessor method |
| 148 |
my $attributes = $self->_result->borrower_attributes->search( { code => $code } ); |
148 |
no strict 'refs'; |
| 149 |
my $values = []; |
149 |
if ( !defined *{ ref($self) . "::$code" }{CODE} ) { |
| 150 |
while ( my $attribute = $attributes->next ) { |
150 |
if ( $attr->repeatable ) { |
| 151 |
push @$values, $attribute->attribute; |
151 |
*{ ref($self) . "::$code" } = sub { |
| 152 |
} |
152 |
my ($self) = @_; |
| 153 |
return $values; |
153 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
| 154 |
}; |
154 |
my $attributes = $self->_result->borrower_attributes->search( { code => $code } ); |
| 155 |
} else { |
155 |
my $values = []; |
| 156 |
*{ ref($self) . "::$code" } = sub { |
156 |
while ( my $attribute = $attributes->next ) { |
| 157 |
my ($self) = @_; |
157 |
push @$values, $attribute->attribute; |
| 158 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
158 |
} |
| 159 |
my $attribute = $self->_result->borrower_attributes->search( { code => $code } )->first; |
159 |
return $values; |
| 160 |
return $attribute ? $attribute->attribute : undef; |
160 |
}; |
| 161 |
}; |
161 |
} else { |
|
|
162 |
*{ ref($self) . "::$code" } = sub { |
| 163 |
my ($self) = @_; |
| 164 |
return $self->_result->get_column($code) if $self->_result->has_column($code); |
| 165 |
my $attribute = $self->_result->borrower_attributes->search( { code => $code } )->first; |
| 166 |
return $attribute ? $attribute->attribute : undef; |
| 167 |
}; |
| 168 |
} |
| 162 |
} |
169 |
} |
| 163 |
} |
170 |
} |
| 164 |
} |
|
|
| 165 |
|
171 |
|
| 166 |
if ($found) { |
172 |
if ($found) { |
| 167 |
return $self->$name(); |
173 |
$self->$name(); |
| 168 |
} else { |
174 |
} else { |
| 169 |
my $wt = 'SUPER::' . $name; |
175 |
$error->rethrow; |
| 170 |
return $self->$wt(@args); |
176 |
} |
| 171 |
} |
177 |
} |
| 172 |
} |
178 |
} |
| 173 |
|
179 |
|
| 174 |
- |
|
|