Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to ensure a Perl version exists in PerlVersion #23

Open
preaction opened this issue Jun 9, 2018 · 0 comments
Open

Add method to ensure a Perl version exists in PerlVersion #23

preaction opened this issue Jun 9, 2018 · 0 comments

Comments

@preaction
Copy link
Member

Right now, the correct way to ensure a Perl version exists in the perl_version table is to do:

my $result = $schema->resultset( 'PerlVersion' )->find_or_create({ version => '5.26.0' });

This is less than optimal for two reasons:

  1. We often don't care to get the result object back, we just need to ensure that the Perl version exists in the database.
  2. This code requires the reader to know that the version field is parsed to find all the other information in the perl_version table. If some other field is used instead, like perl, the data will not be correct.

It would be better if we had a method named ensure_exists that takes a single argument, the Perl version string. It would be called like this:

$schema->resultset( 'PerlVersion' )->ensure_exists( '5.26.0' );

This reads better, and we can improve performance slightly inside by not creating a result object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant