GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Venus::Role::Buildable(3) User Contributed Perl Documentation Venus::Role::Buildable(3)

Venus::Role::Buildable - Buildable Role

Buildable Role for Perl 5

  package Example;
  use Venus::Class;
  with 'Venus::Role::Buildable';
  attr 'test';
  package main;
  my $example = Example->new;
  # $example->test;

This package modifies the consuming package and provides methods for hooking into object construction of the consuming class, e.g. handling single-arg object construction.

This package provides the following methods:

  build_arg(any $data) (hashref)

The build_arg method, if defined, is only called during object construction when a single non-hashref is provided.

Since 0.01

build_arg example 1
  package Example1;
  use Venus::Class;
  attr 'x';
  attr 'y';
  with 'Venus::Role::Buildable';
  sub build_arg {
    my ($self, $data) = @_;
    $data = { x => $data, y => $data };
    return $data;
  }
  package main;
  my $example = Example1->new(10);
  # $example->x;
  # $example->y;
    

  build_args(hashref $data) (hashref)

The build_args method, if defined, is only called during object construction to hook into the handling of the arguments provided.

Since 0.01

build_args example 1
  package Example2;
  use Venus::Class;
  attr 'x';
  attr 'y';
  with 'Venus::Role::Buildable';
  sub build_args {
    my ($self, $data) = @_;
    $data->{x} ||= int($data->{x} || 100);
    $data->{y} ||= int($data->{y} || 100);
    return $data;
  }
  package main;
  my $example = Example2->new(x => 10, y => 10);
  # $example->x;
  # $example->y;
    

  build_nil(hashref $data) (any)

The build_nil method, if defined, is only called during object construction when a single empty hashref is provided.

Since 0.01

build_nil example 1
  package Example4;
  use Venus::Class;
  attr 'x';
  attr 'y';
  with 'Venus::Role::Buildable';
  sub build_nil {
    my ($self, $data) = @_;
    $data = { x => 10, y => 10 };
    return $data;
  }
  package main;
  my $example = Example4->new({});
  # $example->x;
  # $example->y;
    

  build_self(hashref $data) (object)

The build_self method, if defined, is only called during object construction after all arguments have been handled and set.

Since 0.01

build_self example 1
  package Example3;
  use Venus::Class;
  attr 'x';
  attr 'y';
  with 'Venus::Role::Buildable';
  sub build_self {
    my ($self, $data) = @_;
    die if !$self->x;
    die if !$self->y;
    return $self;
  }
  package main;
  my $example = Example3->new(x => 10, y => 10);
  # $example->x;
  # $example->y;
    

Awncorp, "awncorp@cpan.org"

Copyright (C) 2022, Awncorp, "awncorp@cpan.org".

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.

2023-11-27 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.