File: VSTRING.pm

package info (click to toggle)
libdata-printer-perl 1.000001-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 692 kB
  • sloc: perl: 4,208; makefile: 7
file content (30 lines) | stat: -rw-r--r-- 859 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Data::Printer::Filter::VSTRING;
use strict;
use warnings;
use Data::Printer::Filter;
use Data::Printer::Common;

filter 'VSTRING' => \&parse;

sub parse {
    my ($vstring, $ddp) = @_;
    my $string = '';

    # The reason we don't simply do:
    #   use version 0.77 ();
    # is because it was causing some issues with UNIVERSAL on Perl 5.8 and
    # some versions of version.pm. So now we do it on runtime on the filter.
    # ->parse() will raise an error unless version.pm >= 0.77.
    my $error = Data::Printer::Common::_tryme(sub {
        require version;
        $string = version->parse($$vstring)->normal;
    });
    $string = 'VSTRING object (unable to parse)' if $error;

    if ($ddp->show_tied and my $tie = ref tied $$vstring) {
        $string .= " (tied to $tie)";
    }
    return $ddp->maybe_colorize($string, 'vstring');
};

1;