Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
ensembl-gh-mirror
ensembl-hive
Commits
77f376b0
Commit
77f376b0
authored
Apr 09, 2014
by
Leo Gordon
Browse files
allow anonymous hashrefs to be cached in Cacheable/NakedTable classes
parent
88bca4bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
13 deletions
+28
-13
modules/Bio/EnsEMBL/Hive/Cacheable.pm
modules/Bio/EnsEMBL/Hive/Cacheable.pm
+18
-8
modules/Bio/EnsEMBL/Hive/Utils/Collection.pm
modules/Bio/EnsEMBL/Hive/Utils/Collection.pm
+10
-5
No files found.
modules/Bio/EnsEMBL/Hive/Cacheable.pm
View file @
77f376b0
...
...
@@ -29,21 +29,26 @@ sub add_new_or_update {
my
$self
;
if
(
my
$unikey_keys
=
$class
->
unikey
()
)
{
my
%
all
_pairs
=
@_
;
my
%
other
_pairs
=
@_
;
my
%unikey_pairs
;
@unikey_pairs
{
@$unikey_keys
}
=
@all
_pairs
{
@$unikey_keys
};
@unikey_pairs
{
@$unikey_keys
}
=
delete
@other
_pairs
{
@$unikey_keys
};
use
Data::
Dumper
;
local
$
Data::Dumper::
Indent
=
0
;
# we want everything on one line
local
$
Data::Dumper::
Terse
=
1
;
# and we want it without dummy variable names
local
$
Data::Dumper::
Maxdepth
=
1
;
if
(
$self
=
$class
->
collection
()
->
find_one_by
(
%unikey_pairs
)
)
{
# update the rest of the fields
warn
"
Updating
$class
(
"
.
Dumper
(
\
%unikey_pairs
)
.
"
)
\n
";
while
(
my
(
$method
,
$value
)
=
each
%all_pairs
)
{
unless
(
exists
(
$unikey_pairs
{
$method
}
)
)
{
$self
->
$method
(
$value
);
if
(
keys
%other_pairs
)
{
warn
"
Updating
$class
(
"
.
Dumper
(
\
%unikey_pairs
)
.
"
) with (
"
.
Dumper
(
\
%other_pairs
)
.
"
)
\n
";
if
(
ref
(
$self
)
eq
'
HASH
'
)
{
@$self
{
keys
%other_pairs
}
=
values
%other_pairs
;
}
else
{
while
(
my
(
$key
,
$value
)
=
each
%other_pairs
)
{
$self
->
$key
(
$value
);
}
}
}
else
{
warn
"
Found a matching
$class
(
"
.
Dumper
(
\
%unikey_pairs
)
.
"
)
\n
";
}
}
else
{
warn
"
Creating a new
$class
(
"
.
Dumper
(
\
%unikey_pairs
)
.
"
)
\n
";
...
...
@@ -53,7 +58,12 @@ sub add_new_or_update {
}
unless
(
$self
)
{
$self
=
$class
->
new
(
@
_
);
if
(
$class
->
can
('
new
')
)
{
$self
=
$class
->
new
(
@
_
);
}
else
{
$self
=
{
@
_
};
}
$class
->
collection
()
->
add
(
$self
);
}
...
...
modules/Bio/EnsEMBL/Hive/Utils/Collection.pm
View file @
77f376b0
...
...
@@ -44,9 +44,10 @@ sub find_one_by {
ELEMENT:
foreach
my
$element
(
@
{
$self
->
listref
})
{
keys
%method_to_filter_value
;
# sic! This is to "rewind" the each% operator to the beginning each time
while
(
my
(
$method
,
$filter_value
)
=
each
%method_to_filter_value
)
{
next
ELEMENT
unless
(
defined
(
$element
->
$method
())
# either both defined and equal or neither defined
?
defined
(
$filter_value
)
&&
(
$element
->
$method
()
eq
$filter_value
)
while
(
my
(
$filter_name
,
$filter_value
)
=
each
%method_to_filter_value
)
{
my
$actual_value
=
(
ref
(
$element
)
eq
'
HASH
')
?
$element
->
{
$filter_name
}
:
$element
->
$filter_name
();
next
ELEMENT
unless
(
defined
(
$actual_value
)
# either both defined and equal or neither defined
?
defined
(
$filter_value
)
&&
(
$actual_value
eq
$filter_value
)
:
!
defined
(
$filter_value
)
);
}
...
...
@@ -62,8 +63,12 @@ sub find_all_by {
ELEMENT:
foreach
my
$element
(
@
{
$self
->
listref
})
{
keys
%method_to_filter_value
;
# sic! This is to "rewind" the each% operator to the beginning each time
while
(
my
(
$method
,
$filter_value
)
=
each
%method_to_filter_value
)
{
next
ELEMENT
unless
(
$element
->
$method
()
eq
$filter_value
);
while
(
my
(
$filter_name
,
$filter_value
)
=
each
%method_to_filter_value
)
{
my
$actual_value
=
(
ref
(
$element
)
eq
'
HASH
')
?
$element
->
{
$filter_name
}
:
$element
->
$filter_name
();
next
ELEMENT
unless
(
defined
(
$actual_value
)
# either both defined and equal or neither defined
?
defined
(
$filter_value
)
&&
(
$actual_value
eq
$filter_value
)
:
!
defined
(
$filter_value
)
);
}
push
@filtered_elements
,
$element
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment