Changeset 31434
- Timestamp:
- 03/22/09 04:24:59 (4 years ago)
- Location:
- lang/perl/Util-Any/trunk
- Files:
-
- 11 added
- 3 modified
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (1 diff)
-
lib/Util/Any.pm (modified) (5 diffs)
-
t/05-util_any_base-prefix.t (added)
-
t/05-util_any_base.t (added)
-
t/06-perl6-export-attrs-no-args.t (added)
-
t/06-perl6-export-attrs.t (added)
-
t/06-perl6-export-attrs2.t (added)
-
t/07-perl6-export-attrs-no-args.t (added)
-
t/07-perl6-export-attrs.t (added)
-
t/07-perl6-export-attrs2.t (added)
-
t/lib/MyUtilBase.pm (added)
-
t/lib/UtilPerl6ExportAttrs.pm (added)
-
t/lib/UtilPerl6ExportAttrsBase.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Util-Any/trunk/Changes
r26846 r31434 1 1 Revision history for Util-Any 2 3 0.05 2009/03/22 02:35 4 solve the problem using Util::Any with Perl6::Export::Atttrs 5 new feature to inherit Util::Any(-Base and -Perl6ExportAttrs) 2 6 3 7 0.04 2008/12/14 17:34 -
lang/perl/Util-Any/trunk/MANIFEST
r26846 r31434 24 24 t/04-option-select.t 25 25 t/04-option-except.t 26 t/05-util_any_base-prefix.t 27 t/05-util_any_base.t 28 t/06-perl6-export-attrs.t 29 t/06-perl6-export-attrs2.t 30 t/06-perl6-export-attrs-no-args.t 31 t/07-perl6-export-attrs.t 32 t/07-perl6-export-attrs2.t 33 t/07-perl6-export-attrs-no-args.t 26 34 t/lib/MyUtil.pm 35 t/lib/MyUtilBase.pm 36 t/lib/UtilPerl6ExportAttrs.pm 37 t/lib/UtilPerl6ExportAttrsBase.pm -
lang/perl/Util-Any/trunk/lib/Util/Any.pm
r26846 r31434 17 17 sub import { 18 18 my $pkg = shift; 19 my $caller = (caller)[0]; 20 21 return $pkg->_base_import($caller, @_) if @_ and $_[0] =~/^-\w+$/; 19 22 20 23 no strict 'refs'; 21 24 22 25 my $config = ${$pkg . '::Utils'}; 23 my $caller = (caller)[0];24 26 my %want; 25 27 my %opt = (prefix => 0, module_prefix => 0, debug => 0); … … 94 96 } 95 97 } 98 if ($pkg->_use_perl6_export_attrs) { 99 no strict 'refs'; 100 no warnings; 101 my $pkg_utils = ${$pkg . '::Utils'}; 102 my @arg = defined $pkg_utils ? (grep !exists $pkg_utils->{$_}, @_) 103 : (grep !exists $Utils->{$_}, @_); 104 if (@_ and @arg) { 105 eval "package $caller; $pkg" . '->Perl6::Export::Attrs::_generic_import(@arg);'; 106 } elsif (!@_) { 107 eval "package $caller; $pkg" . '->Perl6::Export::Attrs::_generic_import;'; 108 } 109 } 96 110 } 97 111 112 sub _base_import { 113 my ($pkg, $caller, @flgs) = @_; 114 { 115 no strict 'refs'; 116 push @{"${caller}::ISA"}, __PACKAGE__; 117 } 118 119 while (my $flg = shift @flgs) { 120 if (lc($flg) eq '-perl6exportattrs') { 121 eval "use Perl6::Export::Attrs ();"; 122 no strict 'refs'; 123 *{$caller . '::MODIFY_CODE_ATTRIBUTES'} = \&Perl6::Export::Attrs::_generic_MCA; 124 *{$caller . '::_use_perl6_export_attrs'} = sub { 1 }; 125 } 126 } 127 } 128 129 sub _use_perl6_export_attrs { 0 } 130 98 131 =head1 NAME 99 132 … … 106 139 =cut 107 140 108 our $VERSION = '0.0 4';141 our $VERSION = '0.05'; 109 142 110 143 =head1 SYNOPSIS … … 325 358 326 359 use Clone qw/clone/; 327 use base qw/Util::Any/;360 use Util::Any -Base; # or use base qw/Util::Any/; 328 361 our $Utils = clone $Util::Any::Utils; 329 362 push @{$Utils->{list}}, qw/Your::Favorite::List::Utils/; … … 334 367 335 368 use Util::Yours qw/list/; 369 370 =head1 USE Perl6::Export::Attrs in YOUR OWN UTIL MODULE 371 372 Perl6::Export::Attrs overrides caller package's import method. 373 So, when your module use Perl6::Export::Attrs, Util::Any cannot work. 374 375 Util::Any provides option to solve this prolblem. 376 Write the follwoing instead of "use Util::Any -Base" or "use base qw/Util::Any/". 377 378 use Util::Any -Perl6ExportAttrs; 379 380 example; 381 382 package Util::Yours; 383 384 use Clone qw/clone/; 385 use Util::Any -Perl6ExportAttrs; 386 our $Utils = clone $Util::Any::Utils; 387 push @{$Utils->{list}}, qw/Your::Favorite::List::Utils/; 388 389 sub foo :Export(:DEFAULT) { 390 return "foo!"; 391 } 392 393 sub bar :Export(:bar) { 394 return "bar!"; 395 } 396 397 1; 398 399 Or you can write your own import method and BEGIN block like the follwoing. 400 401 package UtilPerl6ExportAttr; 402 403 use strict; 404 use base qw/Util::Any/; 405 use Clone qw/clone/; 406 407 BEGIN { 408 use Perl6::Export::Attrs (); 409 no strict 'refs'; 410 *{__PACKAGE__ . '::MODIFY_CODE_ATTRIBUTES'} = \&Perl6::Export::Attrs::_generic_MCA; 411 } 412 413 our $Utils = clone $Util::Any::Utils; 414 $Utils->{your_list} = [ 415 ['List::Util', '', [qw(first min sum)]], 416 ]; 417 418 sub import { 419 my $pkg = shift; 420 my $caller = (caller)[0]; 421 422 no strict 'refs'; 423 eval "package $caller; $pkg" . '->Util::Any::import(@_);'; 424 my @arg = grep !exists $Utils->{$_}, @_; 425 if (@_ and @arg) { 426 eval "package $caller; $pkg" . '->Perl6::Export::Attrs::_generic_import(@arg)'; 427 } elsif (!@_) { 428 eval "package $caller; $pkg" . '->Perl6::Export::Attrs::_generic_import'; 429 } 430 return; 431 } 432 433 sub foo :Export(:DEFAULT) { 434 return "foo!"; 435 } 436 437 1; 336 438 337 439 =head2 $Utils STRUCTURE
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)