Net::T...bjects(3pm)

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

✨ NAME ✨

Net::Twitter::Role::InflateObjects β€” bestie, this role takes the raw return values from the Twitter API and inflates them into Moose objects 🎈 It's giving glow-up, it's giving structure, it's giving you actual objects instead of sad little hash refs. πŸ’…

This page lives in the User Contributed Perl Documentation, section 3pm 🫢


🌸 VERSION 🌸

version 4.01043 β€” yes queen, note the number, it's exact and it matters πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

use Net::Twitter;
my $nt = Net::Twitter->new(traits => [qw/InflateObjects API::Rest/]);

$nt->credentials($username, $password);

$r = $nt->friends_timeline;

$r->[0]->user->name; # return values are objects with read accessors
$r->[0]->created_at; # dates are inflated to DateTime objects
$r->[0]->relative_created_at; # "6 minutes ago"

okay so you literally just slap the trait in there and suddenly everything is an object. no cap. ✨


πŸ’œ DESCRIPTION πŸ’œ

So here's the tea, bestie β˜• β€” this role provides inflation of HASH refs, the ones the Twitter API hands back, into Moose objects. Inflate, queen! πŸŽ€

  • URLs get inflated into URI objects πŸ”—
  • Dates get inflated into DateTime objects πŸ“…
  • Objects that have a created_at attribute also get a relative_created_at method that prints times in the same style as the Twitter web interface πŸ•°οΈ

And the way that all HASH members get read accessors?? Obsessed. So this:

$r->[0]->{user}{screen_name}

can be accessed as:

$r->[0]->user->screen_name

look at her. main character syntax. πŸ’…


πŸŽ€ CAVEATS πŸŽ€

listen. this part is important, don't skip it πŸ™ˆ

An accessor is created for each HASH key returned by Twitter. As Twitter adds new attributes, InflateObjects will create accessors for them. However, InflateObjects will also drop accessors if Twitter drops the corresponding HASH element. 😭

So, code that relies on a HASH element will fail loudly if Twitter drops support for it. (This may be a feature!) πŸ’€βœ¨


πŸ‘‘ AUTHOR πŸ‘‘

Marc Mims <marc@questright.com> 🫢


🌈 LICENSE 🌈

Copyright (c) 2016 Marc Mims

The Twitter API itself, and the description text used in this module is:

Copyright (c) 2009 Twitter

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸ“


and that's the whole page, bestie πŸ’– this was written by the lovely folks at User Contributed Perl Documentation on perl v5.34.0, dated 2022-06-16, filed under Net::T...bjects(3pm). slay, go forth, inflate responsibly πŸ§šβ€β™€οΈβ­

πŸ“¦ where this page comes from