From 568c7a442188ff8d420622a7a9b5cac4c011aab1 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 10 Nov 2016 14:51:03 +0000 Subject: allow building QRCode with just a string --- lib/Data/QRCode.pm | 9 +++++++++ t/qrcode.t | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Data/QRCode.pm b/lib/Data/QRCode.pm index 74896c9..649e1f9 100644 --- a/lib/Data/QRCode.pm +++ b/lib/Data/QRCode.pm @@ -34,6 +34,15 @@ has input_data => ( isa => Str, ); +around BUILDARGS => sub { + my ($orig,$class,@args) = @_; + + return { input_data => $args[0] } + if @args == 1 && !ref $args[0]; + + return $class->$orig(@args); +}; + has _result => ( is => 'lazy', init_arg => undef, diff --git a/t/qrcode.t b/t/qrcode.t index 14e8bd7..7e08a7f 100644 --- a/t/qrcode.t +++ b/t/qrcode.t @@ -4,9 +4,7 @@ use warnings; use Test2::Bundle::Extended; use Data::QRCode; -my $qr = Data::QRCode->new({ - input_data => 'some words', -}); +my $qr = Data::QRCode->new('some words'); my $text_matrix = $qr->map( sub{ -- cgit v1.2.3