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::Prototype(3) User Contributed Perl Documentation Venus::Prototype(3)

Venus::Prototype - Prototype Class

Prototype Class for Perl 5

  package main;
  use Venus::Prototype;
  my $prototype = Venus::Prototype->new(
    '$counter' => 0,
    '&decrement' => sub { $_[0]->counter($_[0]->counter - 1) },
    '&increment' => sub { $_[0]->counter($_[0]->counter + 1) },
  );
  # bless({value => {...}}, 'Venus::Prototype')
  # $prototype->counter # 0
  # $prototype->increment # 1
  # $prototype->counter # 1
  # $prototype->decrement # 0
  # $prototype->counter # 0

This package provides a simple construct for enabling prototype-base programming. Properties can be called as methods when prefixed with a dollar or ampersand symbol. See "call" for more details.

This package inherits behaviors from:

Venus::Kind::Utility

This package integrates behaviors from:

Venus::Role::Buildable

Venus::Role::Proxyable

Venus::Role::Valuable

This package provides the following methods:

  apply(hashref $data) (Venus::Prototype)

The apply method extends the underlying data structure by merging the data provided, and then returns the invocant.

Since 1.50

apply example 1
  package main;
  my $person = Venus::Prototype->new({
    '$name' => '',
  });
  $person->apply;
  # bless({value => {'$name' => ''}}, 'Venus::Prototype')
    
apply example 2
  package main;
  my $person = Venus::Prototype->new({
    '$name' => '',
  });
  $person->apply({
    '$name' => 'Elliot Alderson',
  });
  # bless({value => {'$name' => 'Elliot Alderson'}}, 'Venus::Prototype')
    
apply example 3
  package main;
  my $person = Venus::Prototype->new({
    '$name' => '',
    '&greet' => sub {'hello'},
  });
  $person->apply({
    '$name' => 'Elliot Alderson',
  });
  # bless({value => {...}}, 'Venus::Prototype')
    

  call(string $method, any @args) (any)

The call method dispatches method calls based on the method name provided and the state of the object, and returns the results. If the method name provided matches an object property of the same name with an ampersand prefix, denoting a method, then the dispatched method call acts as a method call providing the invocant as the first argument. If the method name provided matches an object property of the same name with a dollar sign prefix, denoting an attribute, then the dispatched method call acts as an attribute accessor call. This method is also useful for calling virtual methods when those virtual methods conflict with the Venus::Prototype methods.

Since 1.50

call example 1
  package main;
  my $person = Venus::Prototype->new({
    '$name' => 'anonymous',
  });
  my $name = $person->call('name');
  # "anonymous"
    
call example 2
  package main;
  my $person = Venus::Prototype->new({
    '$name' => 'anonymous',
  });
  my $name = $person->call('name', 'unidentified');
  # "unidentified"
    

  extend(hashref $data) (Venus::Prototype)

The extend method copies the underlying data structure, merging the data provided if any, and then returns a new prototype object.

Since 1.50

extend example 1
  package main;
  my $mrrobot = Venus::Prototype->new({
    '$name' => 'Edward Alderson',
    '$group' => 'fsociety',
  });
  my $elliot = $mrrobot->extend({
    '$name' => 'Elliot Alderson',
  });
  # bless({value => {...}}, 'Venus::Prototype')
    
extend example 2
  package main;
  my $mrrobot = Venus::Prototype->new({
    '$name' => 'Edward Alderson',
    '$group' => 'fsociety',
    '$login' => { username => 'admin', password => 'secret', },
  });
  my $elliot = $mrrobot->extend({
    '$name' => 'Elliot Alderson',
    '$login' => { password => '$ecr3+', },
  });
  # bless({value => {...}}, 'Venus::Prototype')
    
extend example 3
  package main;
  my $ability = {
    '&access' => sub {time},
  };
  my $person = Venus::Prototype->new;
  my $mrrobot = $person->extend($ability);
  my $elliot = $mrrobot->extend($ability);
  # bless({value => {...}}, 'Venus::Prototype')
    

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.