The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Rope::Variant - Rope variant properties

VERSION

Version 0.38

SYNOPSIS

package Variant;

use Rope;
use Rope::Autoload;
use Rope::Variant;
use Types::Standard qw/Str Object/

variant parser => (
	given => Object,
	when => [
		'Test::Parser::One' => {
			alias => {
				parse_string => 'parse',
				# parse_file exists
			},
		},
		'Random::Parser::Two' => {
			alias => {
				# parse_string exists
				parse_file   => 'parse_from_file',
			},
		},
		'Another::Parser::Three' => {
			alias => {
				parse_string => 'meth_one',
				parse_file   => 'meth_two',
			},
		},
	],
);

variant string => (
	given => Str,
	when => [
		'one' => {
		    run => sub { return "$_[1] - cold, cold, cold inside" },
		},
		'two' => {
		    run => sub { return "$_[1] - don't look at me that way"; },
		},
		'three' => {
		    run => sub { return "$_[1] - how hard will i fall if I live a double life"; },
		},
	],
);

variant string => (
	when => [
		four => {
			run => sub {
				return "$_[1] - we can extend";
			}
		}
	]
);

...

1;

...

my $k = Variant->new();

my $obj = Variant->new(
	string => 'one',
	parser => Test::Parser::One->new
);

$obj->string; # one - cold, cold, cold inside
$obj->parser->parse_string; # lalala land

$obj->string = 'two';
$obj->parser = Random::Parser::Two->new();

$obj->string; # two - don't look at me that way
$obj->parser->parse_string; # lalala land 2

Exports

variant

AUTHOR

LNATION, <email at lnation.org>

BUGS

Please report any bugs or feature requests to bug-rope at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rope. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Rope

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2023 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)