Murat Ünalan > Class-Maker-Examples > Obsessor

Download:
Class-Maker-Examples-0.01_02.tar.gz

Dependencies

Annotate this POD

Module Version: 0.02   Source  

NAME ^

Obsessor - methodcall dispatcher/forwarder

SYNOPSIS ^

  use Class::Maker::Examples::Obsessor;

  use Verify;

  use Class::Maker::Examples::User;

                # binding to a class (a clean object is created)
        {
                my $user = Obsessor->new( target => 'User' );

                $user->email( 'murat.uenalan@gmx.de' );

                $user->firstname( 'Murat' );

                $user->lastname( 'Murat' );

                #$user->blabla();

                print Dumper $user;
        }

                # binding to existing object
        {
                my $user = Obsessor->new( target => new User( firstname => 'Murat', lastname => 'Uenalan' ) );

                $user->email( 'murat.uenalan@gmx.de' );

                $user->firstname( 'Murat' );

                #$user->blabla();

                print Dumper $user;
        }

package Verify::Type;

                our $positivliste = new Verify::Type(

                        desc => 'test access right',

                        pass => { exists_in => { firstname => 1, lastname => 1, email => 1 } },

                        fail => { exists_in => [qw(blabla)] }

                );

package main;

        {
                my $accesstester = new Bouncer( );

                push @{ $accesstester->tests }, new Bouncer::Test( field => 'method', type => 'positivliste' );

                my $user = Obsessor->new();

                        # CAVE: target is an Class::Maker::Examples::Obsessor method (the only one)

                $user->Obsessor::target( new User( firstname => 'Murat', lastname => 'Uenalan' ) );

                push @{ $user->bouncers }, $accesstester;

                        # bouncer won't reject email, firstname or lastname, because they're in the pass-list

                $user->email( 'muenalan@cpan.org' );

                $user->firstname( 'Murat' );

                $user->lastname( 'Murat' );

                        # bouncer rejects 'blabla' because it's in fail-list

                $user->blabla();

                print Dumper $user;
        }

DESCRIPTION ^

Class::Maker::Examples::Obsessor has nothing to do with a http-server. But, in the very principle it behaves like it. It serves a target class/object and has all might about it. This can be used i.e. to restrict/log/bench/forward/obscure/cache/.. the access to the target. After you plug a target to an Class::Maker::Examples::Obsessor, the resulting object behaves like the original target in terms of methodcalls. But a ref()-call would reveal the object beeing an Class::Maker::Examples::Obsessor in real. Also caller() would be influenced (unfortunately).

EXPORT

None by default.

EXAMPLE "Access restriction"

AUTHOR ^

Murat Ünalan, <muenalan@cpan.org>

SEE ALSO ^

perl(1).

syntax highlighting: