Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl-hive
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
7
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl-hive
Commits
77f376b0
Commit
77f376b0
authored
11 years ago
by
Leo Gordon
Browse files
Options
Downloads
Patches
Plain Diff
allow anonymous hashrefs to be cached in Cacheable/NakedTable classes
parent
88bca4bd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/Bio/EnsEMBL/Hive/Cacheable.pm
+18
-8
18 additions, 8 deletions
modules/Bio/EnsEMBL/Hive/Cacheable.pm
modules/Bio/EnsEMBL/Hive/Utils/Collection.pm
+10
-5
10 additions, 5 deletions
modules/Bio/EnsEMBL/Hive/Utils/Collection.pm
with
28 additions
and
13 deletions
modules/Bio/EnsEMBL/Hive/Cacheable.pm
+
18
−
8
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
);
}
...
...
This diff is collapsed.
Click to expand it.
modules/Bio/EnsEMBL/Hive/Utils/Collection.pm
+
10
−
5
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
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment