Moonshine-Component

 view release on metacpan or  search on metacpan

lib/Moonshine/Component.pm  view on Meta::CPAN

package Moonshine::Component;

use strict;
use warnings;

use Moonshine::Element;
use Moonshine::Magic;
use Params::Validate qw(:all);
use Ref::Util qw(:all);
use feature qw/switch/;
no if $] >= 5.017011, warnings => 'experimental::smartmatch';

extends "UNIVERSAL::Object";

our $VERSION = '0.09';

BEGIN {
	my $fields = $Moonshine::Element::HAS{"attribute_list"}->();
	my %html_spec = map { $_ => 0 } @{$fields}, qw/data tag/;

	has (
		html_spec	 => sub { \%html_spec },
		modifier_spec => sub { { } },
	);
}

sub validate_build {
	my $self = shift;
	my %args = validate_with(
		params => $_[0],
		spec   => {
			params => { type => HASHREF },
			spec   => { type => HASHREF },
		}
	);

	my %html_spec   = %{ $self->html_spec };
	my %html_params = ();

	my %modifier_spec   = %{ $self->modifier_spec };
	my %modifier_params = ();

	my %combine = ( %{ $args{params} }, %{ $args{'spec'} } );

	for my $key ( keys %combine ) {
		my $spec = $args{spec}->{$key};
		if ( is_hashref($spec) ) {
			defined $spec->{build} and next;
			if ( exists $spec->{base} ) {
				my $param = delete $args{params}->{$key};
				my $spec  = delete $args{spec}->{$key};
				$html_params{$key} = $param if $param;
				$html_spec{$key}   = $spec  if $spec;
				next;
			}
		}

		if ( exists $html_spec{$key} ) {
			if ( defined $spec ) {
				$html_spec{$key} = delete $args{spec}->{$key};
			}
			if ( exists $args{params}->{$key} ) {
				$html_params{$key} = delete $args{params}->{$key};
			}
			next;
		}
		elsif ( exists $modifier_spec{$key} ) {
			if ( defined $spec ) {
				$modifier_spec{$key} = delete $args{spec}->{$key};



( run in 1.903 second using v1.01-cache-2.11-cpan-6aa56a78535 )