GitLab...:Engine(3pm)

πŸ’– GitLab::API::v4::Mock::Engine πŸ’–

okay bestie, so this is the GitLab...:Engine(3pm) page from the User Contributed Perl Documentation, and it's lowkey one of the cutest little modules ever β€” it's literally a fake GitLab server that lives inside your Perl process. no cap. πŸ¦‹


✨ NAME ✨

GitLab::API::v4::Mock::Engine β€” the module that does the mocking the internals of a GitLab server thing. πŸŽ€


🌸 SYNOPSIS 🌸

here's the vibe, copy-paste ready, no edits:

use GitLab::API::v4::Mock::Engine;

my $engine = GitLab::API::v4::Mock::Engine->new();

my $user = $engine->create_user({
    email    => $email,
    username => $username,
    name     => $name,
    ...,
});

print "User created with ID: $user->{id}\n";

look at that. you spin up an engine, you make a user, you print the ID. main character energy fr fr πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

This module provides the tooling to run a mock of the internal state of a GitLab server. it's giving "I don't need a real server, I have delusions and a hash ref." iconic.

real talk though, bestie: at this time very little is validated. and I mean very little. for example, when you create a user with create_user there is no logic which double checks that you specify the required email field, or that you don't put in fields that are unexpected. the engine is just gonna go "okay queen πŸ’…" and do it anyway. so like, garbage in, garbage out, iykyk.

🧚 ATTRIBUTES 🧚

next_ids

my $ids = $engine->next_ids();

A hash reference containing object types to the next ID. ✨

Used by next_id_for. (the two of them are besties, they only work as a duo 🫢)

users

my $users = $engine->users();
foreach my $user (@$users) { ... }

Returns the full array reference of all users hash references. yes, all of them. the whole roster. the entire friend group. 🌈


⭐ METHODS ⭐

next_id_for

my $id = $engine->next_id_for( 'user' );

Given an object type this will return the next unused ID. it's literally the ID dispenser. one at a time, no reusing, no take-backs. πŸŽ€


πŸ‘‘ USER METHODS πŸ‘‘

user

my $user = $engine->user( $id );

Returns a user hash reference for the given ID. πŸ”

If no user is found with the ID then undef is returned. (so like, vibe check your $id before you get your hopes up 😭)

create_user

my $user = $engine->create_user( $user );
my $id = $user->{id};

Takes a user hash reference, sets the id field, and stores it in users. so it doesn't just hand you an ID, it assigns one and files your little user away in the collection. ✨

Returns the updated user hash reference. periodt.

update_user

my $user = $engine->update_user( $id, $new_user_data );

Takes the ID of the user to update and a hash reference of fields to update. glow-up in progress πŸ’–

Returns the updated user hash reference.

delete_user

my $user = $engine->delete_user( $id );

Deletes the user with the specified ID from users. πŸ’€ bye bestie!

If no user is found with the ID then undef is returned. Otherwise the user hash reference is returned. so you either get a ghost or you get the body β€” either way you get something back, which is honestly more than most people give you.


🫢 SUPPORT 🫢

See "SUPPORT" in GitLab::API::v4.


🌸 AUTHORS 🌸

See "AUTHORS" in GitLab::API::v4.


πŸ“œ LICENSE πŸ“œ

See "LICENSE" in GitLab::API::v4.


and that's the whole page, bestie!! no notes, 10/10, would mock again πŸ’…

this was brought to you by perl v5.36.0, dated 2023-06-13, filed under GitLab...:Engine(3pm) β€” mwah, slay, bye! πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from