Hades-Macro-YAML

 view release on metacpan or  search on metacpan

macro-yaml.hades  view on Meta::CPAN

lib lib
tlib t
author LNATION
email email@lnation.org
version 0.04
Hades::Macro::YAML base Hades::Macro {
	abstract { Hades macro helpers for YAML }
	synopsis {
Quick summary of what the module does:

	Hades->run({
		eval => q|
			macro {
				YAML
			}
			Kosmos { 
				geras $file :t(Str) :d('path/to/file.yml') { 
					€yaml_load_file($file);
				}
			}
		|;
	});

	... generates ...

	package Kosmos;
	use strict;
	use warnings;
	use YAML::XS;
	our $VERSION = 0.01;

	sub new {
		my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
		my $self      = bless {}, $cls;
		my %accessors = ();
		for my $accessor ( keys %accessors ) {
			my $param
			    = defined $args{$accessor}
			    ? $args{$accessor}
			    : $accessors{$accessor}->{default};
			my $value
			    = $self->$accessor( $accessors{$accessor}->{builder}
				? $accessors{$accessor}->{builder}->( $self, $param )
				: $param );
			unless ( !$accessors{$accessor}->{required} || defined $value ) {
				die "$accessor accessor is required";
			}
		}
		return $self;
	}

	sub geras {
		my ( $self, $file ) = @_;
		$file = defined $file ? $file : 'path/to/file.yml';
		if ( !defined($file) || ref $file ) {
			$file = defined $file ? $file : 'undef';
			die qq{Str: invalid value $file for variable \$file in method geras};
		}

		YAML::XS::LoadFile($file);
	}

	1;

	}
	our $YAML_CLASS $CLASS_LOADED



( run in 1.487 second using v1.01-cache-2.11-cpan-140bd7fdf52 )