New upstream version 1.000001
gregor herrmann
3 years ago
0 | 0 | Revision history for Data-Printer |
1 | ||
2 | 1.0.1 2021-02-25 | |
3 | BUG FIXES: | |
4 | - properly parse the "n" option in regexes | |
5 | - fix unwrap of __PACKAGE__, __FILENAME__ and __LINE__ | |
6 | on caller_message (GH#156) | |
7 | - add a single space between caller message and data when | |
8 | caller_message_newline is false | |
9 | - proper colorization on caller message. | |
10 | OTHER: | |
11 | - improve documentation on caller message behavior | |
12 | - document caveat of printing array/hash slices (GH#152) | |
13 | - fix broken link in documentation (GH#155) | |
14 | - improve tip on how to make a drop-in replacement | |
15 | to Data::Dumper (GH#154) | |
1 | 16 | |
2 | 17 | 1.0.0 2021-02-24 |
3 | 18 | We are really excited to finally bring to you Data::Printer 1.0.0 \o/ |
52 | 52 | "url" : "https://github.com/garu/Data-Printer" |
53 | 53 | } |
54 | 54 | }, |
55 | "version" : "1.000000", | |
55 | "version" : "1.000001", | |
56 | 56 | "x_serialization_backend" : "JSON::PP version 4.06" |
57 | 57 | } |
27 | 27 | bugtracker: https://github.com/garu/Data-Printer/issues/ |
28 | 28 | license: http://dev.perl.org/licenses/ |
29 | 29 | repository: https://github.com/garu/Data-Printer |
30 | version: '1.000000' | |
30 | version: '1.000001' | |
31 | 31 | x_serialization_backend: 'CPAN::Meta::YAML version 0.018' |
10 | 10 | |
11 | 11 | # a regex to parse a regex. Talk about full circle :) |
12 | 12 | # note: we are not validating anything, just grabbing modifiers |
13 | if ($val =~ m/\(\?\^?([uladxismpogce]*)(?:\-[uladxismpogce]+)?:(.*)\)/s) { | |
13 | if ($val =~ m/\(\?\^?([uladxismnpogce]*)(?:\-[uladxismnpogce]+)?:(.*)\)/s) { | |
14 | 14 | my ($modifiers, $parsed_val) = ($1, $2); |
15 | 15 | $string = $ddp->maybe_colorize($parsed_val, 'regex'); |
16 | 16 | if ($modifiers) { |
752 | 752 | sub _write_label { |
753 | 753 | my ($self) = @_; |
754 | 754 | return '' unless $self->caller_info; |
755 | my @caller = caller 2; | |
755 | my @caller = caller 1; | |
756 | 756 | |
757 | 757 | my $message = $self->caller_message; |
758 | 758 | |
760 | 760 | $message =~ s/\b__FILENAME__\b/$caller[1]/g; |
761 | 761 | $message =~ s/\b__LINE__\b/$caller[2]/g; |
762 | 762 | |
763 | return $message . ($self->caller_message_newline ? "\n" : ''); | |
763 | my $separator = $self->caller_message_newline ? "\n" : ' '; | |
764 | $message = $self->maybe_colorize($message, 'caller_info'); | |
765 | $message = $self->caller_message_position eq 'before' | |
766 | ? $message . $separator | |
767 | : $separator . $message | |
768 | ; | |
769 | return $message; | |
764 | 770 | } |
765 | 771 | |
766 | 772 | sub maybe_colorize { |
967 | 973 | linebreaks. (default: 'auto') |
968 | 974 | |
969 | 975 | |
976 | =head2 Caller Information | |
977 | ||
978 | Data::Printer can add an informational message to every call to C<p()> or | |
979 | C<np()> if you enable C<caller_info>. So for example if you write: | |
980 | ||
981 | my $var = "meep!"; | |
982 | p $var, caller_info => 1; | |
983 | ||
984 | this will output something like: | |
985 | ||
986 | Printing in line 2 of myapp.pl: | |
987 | "meep!" | |
988 | ||
989 | The following options let you customize the message and how it is displayed. | |
990 | ||
991 | =head3 caller_info | |
992 | ||
993 | Set this option to a true value to display a L<message|/caller_message> next | |
994 | to the data being printed. (default: 0) | |
995 | ||
996 | =head3 caller_message | |
997 | ||
998 | What message to print when L<caller_info|/caller_info> is true. | |
999 | ||
1000 | Defaults to | |
1001 | "C<< Printing in line __LINE__ of __FILENAME__ >>". | |
1002 | ||
1003 | If the special strings C<__LINE__>, C<__FILENAME__> or C<__PACKAGE__> are | |
1004 | present in the message, they'll be interpolated into their according value | |
1005 | so you can customize the message at will: | |
1006 | ||
1007 | caller_message = "[__PACKAGE__:__LINE__]" | |
1008 | ||
1009 | =head3 caller_message_newline | |
1010 | ||
1011 | When true, skips a line when printing L<caller_message|/caller_message>. | |
1012 | When false, only a single space is added between the message and the data. | |
1013 | (default: 1) | |
1014 | ||
1015 | =head3 caller_message_position | |
1016 | ||
1017 | This option controls where the L<caller_message|/caller_message> will appear | |
1018 | in relation to the code being printed. Can be set to 'before' or 'after'. A | |
1019 | line is always skipped between the message and the data (either before or | |
1020 | after), unless you set L<caller_message_newline|/caller_message_newline> to 0. | |
1021 | (default: 'before') | |
1022 | ||
1023 | ||
970 | 1024 | =head2 General Options |
971 | 1025 | |
972 | 1026 | =head3 arrows |
976 | 1030 | should it print reference arrows. Possible values are 'all' (e.g |
977 | 1031 | C<< var->{x}->[y]->[z] >>), 'first' (C<< var->{x}[y][z] >>) or 'none' |
978 | 1032 | (C<< var{x}[y][z] >>). Default is 'none'. |
979 | ||
980 | =head3 caller_info | |
981 | ||
982 | Set this option to a true value to display a L<message|/caller_message> next | |
983 | to the data being printed. (default: 0) | |
984 | ||
985 | =head3 caller_message | |
986 | ||
987 | What message to print when L<caller_info|/caller_info> is true. Defaults to | |
988 | "C<< Printing in line __LINE__ of __FILENAME__ >>". | |
989 | ||
990 | =head3 caller_message_newline | |
991 | ||
992 | When true, skips a line when printing L<caller_message|/caller_message> (default: 1) | |
993 | ||
994 | =head3 caller_message_position | |
995 | ||
996 | This option controls where the L<caller_message|/caller_message> will appear | |
997 | in relation to the code being printed. Can be set to 'before' or 'after'. A | |
998 | line is always skipped between the message and the data (either before or | |
999 | after), unless you set L<caller_message_newline|/caller_message_newline> to 0. | |
1000 | (default: 'before') | |
1001 | 1033 | |
1002 | 1034 | =head3 colored |
1003 | 1035 |
4 | 4 | use Data::Printer::Common; |
5 | 5 | use Data::Printer::Config; |
6 | 6 | |
7 | our $VERSION = '1.000000'; | |
7 | our $VERSION = '1.000001'; | |
8 | 8 | $VERSION = eval $VERSION; |
9 | 9 | |
10 | 10 | my $rc_arguments; |
688 | 688 | Notice that B<< you can do this without adding Data::Printer as a dependency >> |
689 | 689 | to your project! Just write your sub and it will be called with the object to |
690 | 690 | be printed and a C<$ddp> object ready for you. See |
691 | L<< Data::Printer::Object|/Data::Printer::Object/"Methods and Accessors for Filter Writers" >> | |
691 | L<< Data::Printer::Object|Data::Printer::Object/"Methods and Accessors for Filter Writers" >> | |
692 | 692 | for how to use it to pretty-print your data. |
693 | 693 | |
694 | 694 | Finally, if your object implements string overload or provides a method called |
721 | 721 | |
722 | 722 | my @x; |
723 | 723 | p $x[5]; # undef, but will initialize the array with 5 elements (all undef) |
724 | ||
725 | Slices (both array and hash) must be coerced into actual arrays (or hashes) | |
726 | to properly shown. So if you want to print a slice, instead of doing something | |
727 | like this: | |
728 | ||
729 | p @somevar[1..10]; # WRONG! DON'T DO THIS! | |
730 | ||
731 | try one of those: | |
732 | ||
733 | my @x = @somevar[1..10]; p @x; # works! | |
734 | p [ @somevar[1..0] ]->@*; # also works! | |
735 | p @{[@somevar[1..0]]}; # this works too!! | |
724 | 736 | |
725 | 737 | Finally, as mentioned before, you cannot pass anonymous references on the |
726 | 738 | default mode of C<< use_prototypes = 1 >>: |
917 | 929 | complete drop-in replacement for Template::Plugin::Dumper so you don't even have |
918 | 930 | to change your previous templates! |
919 | 931 | |
932 | =head2 Migrating from Data::Dumper to Data::Printer | |
933 | ||
934 | If you are porting your code to use Data::Printer instead of | |
935 | Data::Dumper, you could replace: | |
936 | ||
937 | use Data::Dumper; | |
938 | ||
939 | with something like: | |
940 | ||
941 | use Data::Printer; | |
942 | sub Dumper { np @_, colored => 1 } | |
943 | ||
944 | this sub will accept multiple variables just like Data::Dumper. | |
945 | ||
920 | 946 | =head2 Unified interface for Data::Printer and other debug formatters |
921 | 947 | |
922 | 948 | I<< (contributed by Kevin McGrath (catlgrep)) >> |
923 | 949 | |
924 | If you are porting your code to use Data::Printer instead of | |
925 | Data::Dumper or similar, you can just replace: | |
926 | ||
927 | use Data::Dumper; | |
928 | ||
929 | with: | |
930 | ||
931 | use Data::Printer alias => 'Dumper'; | |
932 | ||
933 | making sure to provide Data::Printer with the proper alias for the | |
934 | previous dumping function. | |
935 | ||
936 | If, however, you want a really unified approach where you can easily | |
937 | flip between debugging outputs, use L<Any::Renderer> and its plugins, | |
950 | If you want a really unified approach to easily flip between debugging | |
951 | outputs, use L<Any::Renderer> and its plugins, | |
938 | 952 | like L<Any::Renderer::Data::Printer>. |
939 | 953 | |
940 | 954 | =head2 Printing stack traces with arguments expanded using Data::Printer |
1000 | 1014 | Dotan Dimet, Eden Cardim (edenc), Elliot Shank (elliotjs), Eugen Konkov (KES777), |
1001 | 1015 | Fernando Corrêa (SmokeMachine), Fitz Elliott, Florian (fschlich), |
1002 | 1016 | Frew Schmidt (frew), GianniGi, Graham Knop (haarg), Graham Todd, |
1003 | Gregory J. Oschwald, grr, Håkon Hægland, Nigel Metheringham (nigelm), | |
1017 | Gregory J. Oschwald, grr, Håkon Hægland, Iaroslav O. Kosmina (darviarush), | |
1004 | 1018 | Ivan Bessarabov (bessarabv), J Mash, James E. Keenan (jkeenan), |
1005 | 1019 | Jarrod Funnell (Timbus), Jay Allen (jayallen), Jay Hannah (jhannah), |
1006 | 1020 | jcop, Jesse Luehrs (doy), Joel Berger (jberger), |
1009 | 1023 | Kip Hampton (ubu), Londran, Marcel Grünauer (hanekomu), |
1010 | 1024 | Marco Masetti (grubert65), Mark Fowler (Trelane), Martin J. Evans, |
1011 | 1025 | Matt S. Trout (mst), Maxim Vuets, Michael Conrad, Mike Doherty (doherty), |
1012 | Nicolas R (atoomic), Nuba Princigalli (nuba), Olaf Alders (oalders), | |
1013 | Paul Evans (LeoNerd), Pedro Melo (melo), Philippe Bruhat (BooK), | |
1014 | Przemysław Wesołek (jest), Rebecca Turner (iarna), Renato Cron (renatoCRON), | |
1015 | Ricardo Signes (rjbs), Rob Hoelz (hoelzro), sawyer, Sebastian Willing (Sewi), | |
1016 | Sergey Aleynikov (randir), Slaven Rezić, Stanislaw Pusep (syp), | |
1017 | Stephen Thirlwall (sdt), sugyan, Tai Paul, Tatsuhiko Miyagawa (miyagawa), | |
1018 | Thomas Sibley (tsibley), Tim Heaney (oylenshpeegul), Torsten Raudssus (Getty), | |
1026 | Nicolas R (atoomic), Nigel Metheringham (nigelm), Nuba Princigalli (nuba), | |
1027 | Olaf Alders (oalders), Paul Evans (LeoNerd), Pedro Melo (melo), | |
1028 | Philippe Bruhat (BooK), Przemysław Wesołek (jest), Rebecca Turner (iarna), | |
1029 | Renato Cron (renatoCRON), Ricardo Signes (rjbs), Rob Hoelz (hoelzro), | |
1030 | Salve J. Nilsen (sjn), sawyer, Sebastian Willing (Sewi), | |
1031 | Sébastien Feugère (smonff), Sergey Aleynikov (randir), Slaven Rezić, | |
1032 | Stanislaw Pusep (syp), Stephen Thirlwall (sdt), sugyan, Tai Paul, | |
1033 | Tatsuhiko Miyagawa (miyagawa), Thomas Sibley (tsibley), | |
1034 | Tim Heaney (oylenshpeegul), Toby Inkster (tobyink), Torsten Raudssus (Getty), | |
1019 | 1035 | Tokuhiro Matsuno (tokuhirom), trapd00r, Tsai Chung-Kuan, vividsnow, |
1020 | 1036 | Wesley Dal`Col (blabos), y, Yanick Champoux (yanick). |
1021 | 1037 |