package HTML::String::Value;
use strictures 1;
+use UNIVERSAL::ref;
use Safe::Isa;
use Data::Munge;
-sub op_factory {
- my ($op) = @_;
-
- return eval q|sub {
- my ($self, $str) = @_;
-
- if ( $str->$_isa(__PACKAGE__) ) {
- return $self->unescaped_string | . $op . q| $str->unescaped_string;
- }
- else {
- return $self->unescaped_string | . $op . q| $str;
- }
- }|;
-}
-
use overload
'""' => 'escaped_string',
'.' => 'dot',
'.=' => 'dot_equals',
-
- 'cmp' => op_factory('cmp'),
- 'eq' => op_factory('eq'),
- '<=>' => op_factory('<=>'),
- '==' => op_factory('=='),
- '%' => op_factory('%'),
- '+' => op_factory('+'),
- '-' => op_factory('-'),
- '*' => op_factory('*'),
- '/' => op_factory('/'),
- '**' => op_factory('**'),
- '>>' => op_factory('>>'),
- '<<' => op_factory('<<'),
+ '=' => 'clone',
fallback => 1,
;
sub new {
my ($class, @raw_parts) = @_;
- my @parts = map { ref($_) eq 'ARRAY' ? $_ : [$_] } @raw_parts;
+ my @parts = map {
+ if (ref($_) eq 'ARRAY') {
+ $_
+ } elsif ($_->$_isa(__PACKAGE__)) {
+ @{$_->{parts}}
+ } else {
+ [ $_, 0 ]
+ }
+ } @raw_parts;
my $self = bless { parts => \@parts }, $class;
return $self;
}
+sub clone {
+ my $self = shift;
+
+ return ref($self)->new(@{$self->{parts}});
+}
+
+sub ref { '' }
+
1;