- Timestamp:
- 09/14/09 03:46:30 (4 years ago)
- Location:
- lang/perl/Util-Any/trunk
- Files:
-
- 7 added
- 4 modified
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (4 diffs)
-
lib/Util/Any.pm (modified) (16 diffs)
-
t/01-unit.t (added)
-
t/01-util.t (modified) (1 diff)
-
t/02-util-func-scalar-prefix-sign.t (added)
-
t/13-inherit.t (added)
-
t/lib/Inherit.pm (added)
-
t/lib/InheritSub.pm (added)
-
t/lib/One.pm (added)
-
t/lib/Two.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Util-Any/trunk/Changes
r32282 r35361 1 1 Revision history for Util-Any 2 2 3 0.09 2009/09/13 03:31 4 Fix bug, prefix doesn't work when using '-kind' style. 5 6 0.08 2009/09/11 15:58 7 support Sub::Exporter 8 support some of exporting ways of Sub::Exporter 9 3 10 0.07 2009/04/12 03:58 4 support Sub::Exporter 5 support some of exporting ways from Sub::Exporter 11 Fix bug when inheriting 6 12 7 13 0.06 2009/03/22 14:55 -
lang/perl/Util-Any/trunk/MANIFEST
r32282 r35361 9 9 t/pod-coverage.t 10 10 t/pod.t 11 t/01-unit.t 12 t/01-util.t 11 13 t/01-util-kind-list.t 12 14 t/01-util-kind-scalar.t … … 22 24 t/01-util-kind-my-prefix.t 23 25 t/02-util-func-scalar-prefix.t 26 t/02-util-func-scalar-prefix-sign.t 24 27 t/01-util-kind-all-prefix.t 25 28 t/03-debug.t … … 48 51 t/11-sub-exporter-full-all.t 49 52 t/12-sub-exporter-like-export.t 53 t/13-inherit.t 50 54 t/lib/MyUtil.pm 51 55 t/lib/MyUtilBase.pm … … 57 61 t/lib/UtilSubExporter2.pm 58 62 t/lib/exampleHello.pm 63 t/lib/Inherit.pm 64 t/lib/InheritSub.pm 65 t/lib/One.pm 66 t/lib/Two.pm -
lang/perl/Util-Any/trunk/lib/Util/Any.pm
r33696 r35361 42 42 $prefix = $kind_prefix ? $kind_prefix : 43 43 ($opt{module_prefix} and $module_prefix) ? $module_prefix : 44 $opt{prefix} ? lc( $kind) . '_': '';44 $opt{prefix} ? lc(join "",$kind =~m{(\w+)}g) . '_': ''; 45 45 46 46 my $evalerror = ''; … … 256 256 =head1 NAME 257 257 258 Util::Any - Export any utilities and To create your own Util::Any258 Util::Any - to export any utilities and to create your own Utilitie module 259 259 260 260 =cut 261 261 262 our $VERSION = '0.0 7';262 our $VERSION = '0.09'; 263 263 264 264 =head1 SYNOPSIS … … 313 313 You can create your own module and use this in the same way as Util::Any like the following. 314 314 315 use YourUtil qw/list/;315 use YourUtil -list; 316 316 317 317 see C<CREATE YOUR OWN Util::Any>, in detail. … … 321 321 =head2 use Util::Any (KIND) 322 322 323 use Util::Any qw/list hash/;323 use Util::Any -list, -hash; 324 324 325 325 Give list of kinds of modules. All functions in moduls are exporeted. … … 327 327 =head2 use Util::Any {KIND => [FUNCTIONS], ...}; 328 328 329 use Util::Any { list => ['uniq'],hash => ['lock_keys']};329 use Util::Any {-list => ['uniq'], -hash => ['lock_keys']}; 330 330 331 331 Give hash ref whose key is kind and value is function names. … … 342 342 add kind prefix to function name. 343 343 344 use Util::Any qw/list/, {prefix => 1};344 use Util::Any -list, {prefix => 1}; 345 345 346 346 list_uniq(1,2,3,4,5); # it is List::More::Utils's uniq function … … 356 356 If you pass debug value, warn or die. 357 357 358 use Util::Any qw/list/, {debug => 1}; # warn359 use Util::Any qw/list/, {debug => 2}; # die358 use Util::Any -list, {debug => 1}; # warn 359 use Util::Any -list, {debug => 2}; # die 360 360 361 361 =back … … 481 481 use Util::Any -Base; # or use base qw/Util::Any/; 482 482 our $Utils = clone $Util::Any::Utils; 483 push @{$Utils->{ list}}, qw/Your::Favorite::List::Utils/;483 push @{$Utils->{-list}}, qw/Your::Favorite::List::Utils/; 484 484 485 485 1; … … 487 487 In your code; 488 488 489 use Util::Yours qw/list/;489 use Util::Yours -list; 490 490 491 491 =head2 $Utils STRUCTURE … … 495 495 $Utils => { 496 496 # simply put module names 497 kind1 => [qw/Module1 Module2 ..../],498 # Module name and its prefix499 kind2 => [ [Module1 => 'module_prefix'], ... ],497 -kind1 => [qw/Module1 Module2 ..../], 498 -# Module name and its prefix 499 -kind2 => [ [Module1 => 'module_prefix'], ... ], 500 500 # limit functions to be exported 501 kind3 => [ [Module1, 'module_prefix', [qw/func1 func2/] ], ... ],501 -kind3 => [ [Module1, 'module_prefix', [qw/func1 func2/] ], ... ], 502 502 # as same as above except not specify modul prefix 503 kind4 => [ [Module1, '', [qw/func1 func2/] ], ... ],503 -kind4 => [ [Module1, '', [qw/func1 func2/] ], ... ], 504 504 }; 505 505 … … 547 547 Util::Any auomaticaly export functions from modules' @EXPORT and @EXPORT_OK. 548 548 In some cases, it is not good idea like Data::Dumper's Dumper and DumperX. 549 Thease 2 functions are same feature. 549 550 550 551 So you can limit functions to be exported. 551 552 552 553 our $Utils = { 553 debug => [554 -debug => [ 554 555 ['Data::Dumper', '', 555 556 ['Dumper']], # only Dumper method is exported. … … 560 561 561 562 our $Utils = { 562 debug => [563 -debug => [ 563 564 ['Data::Dumper', '', 564 565 { -select => ['Dumper'] }, # only Dumper method is exported. … … 573 574 574 575 our $Utils = { 575 debug => [576 -debug => [ 576 577 ['Data::Dumper', '', 577 578 { -except => ['DumperX'] }, # export functions except DumperX … … 588 589 589 590 our $Utils = { 590 list => [591 -list => [ 591 592 [ 592 593 'List::Util', '', … … 603 604 =head2 EXPORTING LIKE Sub::Exporter 604 605 605 It's experimental featrue.not enough tested. and only support '-prefix' and '-as'.606 607 use UtilSubExporter list => {-prefix => 'list__', min => {-as => "list___min"}},606 This featrue is not enough tested. and only support '-prefix' and '-as'. 607 608 use UtilSubExporter -list => {-prefix => 'list__', min => {-as => "list___min"}}, 608 609 # The following is normal Sub::Exporter importing 609 -greet => {-prefix => "greet_"},610 greet => {-prefix => "greet_"}, 610 611 'askme' => {-as => "ask_me"}; 611 612 … … 795 796 L<Exporter>, L<Exporter::Simple>, L<Sub::Exporter> and L<Perl6::Export::Attrs>. 796 797 798 Now I try to make L<Util::All> module based on Util::Any. see the following URL. 799 800 http://github.com/ktat/Util-All 801 797 802 =head1 ACKNOWLEDGEMENTS 798 803 799 804 =head1 COPYRIGHT & LICENSE 800 805 801 Copyright 2008 Ktat, all rights reserved.806 Copyright 2008-2009 Ktat, all rights reserved. 802 807 803 808 This program is free software; you can redistribute it and/or modify it -
lang/perl/Util-Any/trunk/t/01-util.t
r32675 r35361 48 48 } 49 49 50 my @isa = @main::ISA; 51 Util::Any::_base_import('Util::Any', 'main', '-base'); 52 is($main::ISA[-1], 'Util::Any', 'isa'); 53 ok(!defined &main::_use_import_module, 'not defined'); 54 @main::ISA = @isa; 55 56 foreach my $m (['-Exporter' , 'Exporter' ], 57 ['-ExporterSimple' , 'Exporter::Simple' ], 58 ['-SubExporter' , 'Sub::Exporter' ], 59 ['-Perl6ExportAttrs', 'Perl6::Export::Attrs'], 60 ) { 61 Util::Any::_base_import('Util::Any', 'main', $m->[0]); 62 my $file = $m->[1] . '.pm'; 63 $file =~s{::}{/}g; 64 ok(exists $main::INC{$file}, $file); 65 is(&main::_use_import_module(), $m->[1], $m->[1]); 66 undef &main::_use_import_module; 67 @main::ISA = @isa; 68 } 69 70 eval { 71 Util::Any::_base_import('Util::Any', 'main', "Hoge"); 72 }; 73 74 ok($@ =~ /cannot understand/, 'unknown option');
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)