Mock::...:Object(3pm)

πŸ“¦
version 1.111 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’… Mock::...:Object β€” the perl manpage, but make it cute

okay bestie, so this is Mock::...:Object(3pm) from the User Contributed Perl Documentation, and it's literally the object-mocking half of Mock::Quick. sit down, hydrate, let's go ✨


🌸 NAME 🌸

Mock::Quick::Object β€” object mocking for Mock::Quick πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So basically this whole module is object mocking. that's the vibe. that's the whole assignment. πŸ’…

but real talk β€” if you want a better interface, go look at Mock::Quick instead. this one's lowkey the backstage crew, not the main character. iykyk 🫢


✨ SYNOPSIS ✨

here's the whole vibe, no cap:

use Mock::Quick::Object;
use Mock::Quick::Method;

my $obj = Mock::Quick::Object->new(
    foo => 'bar',            # define attribute
    do_it => qmeth { ... },  # define method
    ...
);

is( $obj->foo, 'bar' );
$obj->foo( 'baz' );
is( $obj->foo, 'baz' );

$obj->do_it();

# define the new attribute automatically
$obj->bar( 'xxx' );

# define a new method on the fly
$obj->baz( Mock::Quick::Method->new( sub { ... });

# remove an attribute or method
$obj->baz( \$Mock::Quick::Util::CLEAR );

okay so let's break down the drama πŸ‘‘

  • you spin up a $obj with Mock::Quick::Object->new(...) and just hand it a list of stuff.
  • pass a plain value like foo => 'bar' and boom πŸ’₯ that's an attribute now.
  • pass qmeth { ... } like do_it => qmeth { ... } and boom πŸ’₯ that's a method now.
  • call is( $obj->foo, 'bar' ); and it slays, because foo is 'bar'.
  • then $obj->foo( 'baz' ); β€” and now is( $obj->foo, 'baz' ); passes. the attribute just got rewritten mid-argument, iconic behaviour honestly.
  • $obj->do_it(); β€” call your method, live your truth.
  • $obj->bar( 'xxx' ); β€” define the new attribute automatically ✨ it just appears. no setup. no warning. girlboss.
  • $obj->baz( Mock::Quick::Method->new( sub { ... }); β€” define a new method on the fly 🧚
  • $obj->baz( \$Mock::Quick::Util::CLEAR ); β€” remove an attribute or method. poof. gone. πŸ’€
fr fr, those are the actual lines from the page β€” including the lil' dangling ); in the method one. i'm not fixing it, i'm respecting it. it's giving "authored in 2011 and we love her". 🫢

πŸ‘‘ AUTHORS πŸ‘‘

  • Chad Granum β€” exodist7@gmail.com πŸŽ€

  • Copyright (C) 2011 Chad Granum
  • Mock-Quick is free software; Standard perl licence.
  • Mock-Quick is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
⚠️ bestie that warranty bit is in all caps for a reason β€” no promises, no guarantees, she's free software and she said what she said. πŸ’…

🌈 the cute sign-off 🌈

and that's the whole page, periodt ✨ this was perl v5.34.0, dated 2022-06-15, and it lives its best life under Mock::...:Object(3pm). mwah πŸ’– πŸ¦‹ 🌸

πŸ“¦ where this page comes from