From: Simon Elliott Date: Fri, 20 May 2011 17:59:59 +0000 (+0100) Subject: deprecate long form args X-Git-Tag: release_0.009007_1~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f0ddc273d86f2229d0a20103206ccc7d82078289;hp=a5d7c5f6c5f683b801fda481884ee33892683b30;p=catagits%2FHTML-Zoom.git deprecate long form args --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index 6577fd9..79a1506 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -24,6 +24,8 @@ sub _flatten_stream_of_streams { shift->_zconfig->stream_utils->flatten_stream_of_streams(@_) } +sub set_attr { shift->set_attribute(@_); } + sub set_attribute { my $self = shift; my ($name, $value) = $self->_parse_attribute_args(@_); @@ -43,6 +45,9 @@ sub _parse_attribute_args { my $self = shift; # allow ->add_to_attribute(name => 'value') # or ->add_to_attribute({ name => 'name', value => 'value' }) + + warn "WARNING: Long form args (name => 'class', value => 'x') will be replaced with an incompatible form in the *very near future*." + if(@_ == 1 && $_[0]->{'name'} && $_[0]->{'value'}); my ($name, $value) = @_ > 1 ? @_ : @{$_[0]}{qw(name value)}; return ($name, $self->_zconfig->parser->html_escape($value)); } @@ -51,6 +56,14 @@ sub add_attribute { die "renamed to add_to_attribute. killing this entirely for 1.0"; } +sub add_class { shift->add_to_attribute('class',@_) } + +sub remove_class { shift->remove_attribute('class',@_) } + +sub set_class { shift->set_attribute('class',@_) } + +sub set_id { shift->set_attribute('id',@_) } + sub add_to_attribute { my $self = shift; my ($name, $value) = $self->_parse_attribute_args(@_); diff --git a/t/actions.t b/t/actions.t index 6e1541b..4e3315b 100644 --- a/t/actions.t +++ b/t/actions.t @@ -50,7 +50,7 @@ my ($expect, @ev); ($expect = $tmpl) =~ s/class="main"/class="foo"/; is( - run_for { $_->set_attribute({ name => 'class', value => 'foo' }) }, + run_for { $_->set_attribute( 'class' => 'foo' ) }, $expect, 'set attribute on existing attribute' ); @@ -58,7 +58,7 @@ is( ($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/; is( - run_for { $_->set_attribute({ name => 'foo', value => 'bar' }) }, + run_for { $_->set_attribute( 'foo' => 'bar' ) }, $expect, 'set attribute on non existing attribute' ); @@ -66,7 +66,7 @@ is( ($expect = $tmpl) =~ s/class="main"/class="main foo"/; is( - run_for { $_->add_to_attribute({ name => 'class', value => 'foo' }) }, + run_for { $_->add_to_attribute( 'class' => 'foo' ) }, $expect, 'add attribute on existing attribute' ); @@ -74,7 +74,7 @@ is( ($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/; is( - run_for { $_->add_to_attribute({ name => 'foo', value => 'bar' }) }, + run_for { $_->add_to_attribute( 'foo' => 'bar' ) }, $expect, 'add attribute on non existing attribute' ); diff --git a/t/dwim-autoload.t b/t/dwim-autoload.t index 54de2fd..caf7716 100644 --- a/t/dwim-autoload.t +++ b/t/dwim-autoload.t @@ -100,15 +100,6 @@ like( like( HTML::Zoom ->from_html(q[

Hi!

]) - ->add_to_attribute('p', {name => 'class', value => 'para'}) - ->to_html, - qr/first para/, - 'Got correct from add_to_attribute' -); - -like( - HTML::Zoom - ->from_html(q[

Hi!

]) ->add_to_attribute('p', class => 'para') ->to_html, qr/first para/, @@ -124,15 +115,6 @@ like( 'Got correct from set_attribute' ); -like( - HTML::Zoom - ->from_html(q[

Hi!

]) - ->set_attribute('p', {name => 'class', value => 'para'}) - ->to_html, - qr/class="para"/, - 'Got correct from set_attribute' -); - is( HTML::Zoom ->from_html(q[

Hi!

])