UR::Ob...t::Text(3pm)

πŸ“¦
version 0.470 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

✨ UR::Object::View::Default::Text ✨

okay so bestie, this is a page from the User Contributed Perl Documentation collection, and the whole thing is literally just UR::Object::View::Default::Text β€” object views, but make them text. πŸ’…


πŸŽ€ NAME πŸŽ€

UR::Object::View::Default::Text β€” object views in text format. that's it, that's the whole vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

watch this, it's giving elegant:

  $o = Acme::Product->get(1234);

  # generates a UR::Object::View::Default::Text object:
  $v = $o->create_view(
      toolkit => 'text',
      aspects => [
        'id',
        'name',
        'qty_on_hand',
        'outstanding_orders' => [
          'id',
          'status',
          'customer' => [
            'id',
            'name',
          ]
        ],
      ],
  );

  $txt1 = $v->content;

  $o->qty_on_hand(200);

  $txt2 = $v->content;

so you grab an object, you build a view with toolkit => 'text' and a whole lil nested list of aspects, you ask it for $v->content, you poke the object with $o->qty_on_hand(200), and then $v->content again gives you fresh text. the view stays live, no cap. πŸ”₯


πŸ’– DESCRIPTION πŸ’–

This class implements basic text views of objects. It is used for command-line tools, and it is the base class for other specific text formats like XML, HTML, JSON, etc. so basically it's the main character and everything else is a spin-off. πŸ‘‘


πŸ¦‹ WRITING A SUBCLASS πŸ¦‹

want your own flavor? it's giving inherit and slay:

  # In Acme/Product/View/OutstandingOrders/Text.pm

  package Acme::Product::View::OutstandingOrders::Text;
  use UR;

  class Acme::Product::View::OutstandingOrders::Text {
    is => 'UR::Object::View::Default::Text'
  };

  sub _initial_aspects {
    return (
      'id',
      'name',
      'qty_on_hand',
      'outstanding_orders' => [
        'id',
        'status',
        'customer' => [
          'id',
          'name',
        ]
      ],
    );
  }

  $v = $o->create_view(perspective => 'outstanding orders', toolkit => 'text');
  print $v->content;

you set is => 'UR::Object::View::Default::Text', you override _initial_aspects with your own list of aspects, and then you just create_view(perspective => 'outstanding orders', toolkit => 'text') and print $v->content. iconic. periodt. πŸ’…βœ¨


⭐ SEE ALSO ⭐

  • UR::Object::View
  • UR::Object::View::Toolkit::Text
  • UR::Object

go read those next, iykyk 🫢


and that's the whole page bestie, no crumbs left πŸ“

this little tour was brought to you by perl v5.32.1, dated 2022-01-17 πŸ’œ bye bye, go build some text views, you're doing amazing sweetie 🌈🧚

πŸ“¦ where this page comes from