Skip to content

Commit

Permalink
reintroduce :entry(:alias<foo>) sub-trait
Browse files Browse the repository at this point in the history
should prove useful in using PDF::Class as a base class for PDF::API6.
  • Loading branch information
dwarring committed Jan 7, 2018
1 parent 673f587 commit 6e4d898
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 70 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Release 0.2.7
- [PDF::DAO::Tie] reintroduce method :entry(:alias<foo>) sub-trait. Should
prove useful in using PDF::Class as a base class for PDF::API6.
Release 0.2.6
- [PDF::DAO::Util] setup libpdf at BEGIN time
- Rename or hide overused load() method in various classes/roles
Expand Down
131 changes: 69 additions & 62 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,70 @@
{ "perl" : "6.*",
"name" : "PDF",
"tags" : ["pdf"],
"license" : "Artistic-2.0",
"version" : "0.2.6",
"auth" : "github:p6-pdf",
"api" : "PDF-1.7",
"description" : "Base classes for reading, manipulation and writing of PDF data",
"depends" : [ "Compress::Zlib", "PDF::Grammar", "JSON::Fast", "OpenSSL" ],
"source-url" : "git://github.com/p6-pdf/PDF-p6.git",
"provides" : {

"PDF" : "lib/PDF.pm",

"PDF::Reader" : "lib/PDF/Reader.pm",
"PDF::Writer" : "lib/PDF/Writer.pm",

"PDF::DAO" : "lib/PDF/DAO.pm",
"PDF::DAO::Loader" : "lib/PDF/DAO/Loader.pm",
"PDF::DAO::Coercer" : "lib/PDF/DAO/Coercer.pm",
"PDF::DAO::Array" : "lib/PDF/DAO/Array.pm",
"PDF::DAO::Bool" : "lib/PDF/DAO/Bool.pm",
"PDF::DAO::ByteString" : "lib/PDF/DAO/ByteString.pm",
"PDF::DAO::DateString" : "lib/PDF/DAO/DateString.pm",
"PDF::DAO::TextString" : "lib/PDF/DAO/TextString.pm",
"PDF::DAO::Dict" : "lib/PDF/DAO/Dict.pm",
"PDF::DAO::Int" : "lib/PDF/DAO/Int.pm",
"PDF::DAO::Name" : "lib/PDF/DAO/Name.pm",
"PDF::DAO::Null" : "lib/PDF/DAO/Null.pm",
"PDF::DAO::Real" : "lib/PDF/DAO/Real.pm",
"PDF::DAO::Stream" : "lib/PDF/DAO/Stream.pm",

"PDF::DAO::Tie" : "lib/PDF/DAO/Tie.pm",
"PDF::DAO::Tie::Array" : "lib/PDF/DAO/Tie/Array.pm",
"PDF::DAO::Tie::Hash" : "lib/PDF/DAO/Tie/Hash.pm",

"PDF::DAO::Type::Encrypt" : "lib/PDF/DAO/Type/Encrypt.pm",
"PDF::DAO::Type::Info" : "lib/PDF/DAO/Type/Info.pm",
"PDF::DAO::Type::ObjStm" : "lib/PDF/DAO/Type/ObjStm.pm",
"PDF::DAO::Type::XRef" : "lib/PDF/DAO/Type/XRef.pm",

"PDF::DAO::Util" : "lib/PDF/DAO/Util.pm",

"PDF::IO" : "lib/PDF/IO.pm",
"PDF::IO::Handle" : "lib/PDF/IO/Handle.pm",
"PDF::IO::Str" : "lib/PDF/IO/Str.pm",
"PDF::IO::Blob" : "lib/PDF/IO/Blob.pm",
"PDF::IO::Crypt" : "lib/PDF/IO/Crypt.pm",
"PDF::IO::Crypt::AST" : "lib/PDF/IO/Crypt/AST.pm",
"PDF::IO::Crypt::AES" : "lib/PDF/IO/Crypt/AES.pm",
"PDF::IO::Crypt::RC4" : "lib/PDF/IO/Crypt/RC4.pm",
"PDF::IO::Crypt::PDF" : "lib/PDF/IO/Crypt/PDF.pm",
"PDF::IO::Filter" : "lib/PDF/IO/Filter.pm",
"PDF::IO::Filter::ASCII85" : "lib/PDF/IO/Filter/ASCII85.pm",
"PDF::IO::Filter::ASCIIHex" : "lib/PDF/IO/Filter/ASCIIHex.pm",
"PDF::IO::Filter::Flate" : "lib/PDF/IO/Filter/Flate.pm",
"PDF::IO::Filter::Predictors" : "lib/PDF/IO/Filter/Predictors.pm",
"PDF::IO::Filter::RunLength" : "lib/PDF/IO/Filter/RunLength.pm",
"PDF::IO::IndObj" : "lib/PDF/IO/IndObj.pm",
"PDF::IO::Util" : "lib/PDF/IO/Util.pm",
"PDF::IO::Serializer" : "lib/PDF/IO/Serializer.pm"
}
{
"api" : "PDF-1.7",
"auth" : "github:p6-pdf",
"authors" : [
"David Warring"
],
"build-depends" : [ ],
"depends" : [
"Compress::Zlib",
"PDF::Grammar",
"JSON::Fast",
"OpenSSL"
],
"description" : "Base classes for reading, manipulation and writing of PDF data",
"license" : "Artistic-2.0",
"name" : "PDF",
"perl" : "6.*",
"provides" : {
"PDF" : "lib/PDF.pm",
"PDF::DAO" : "lib/PDF/DAO.pm",
"PDF::DAO::Array" : "lib/PDF/DAO/Array.pm",
"PDF::DAO::Bool" : "lib/PDF/DAO/Bool.pm",
"PDF::DAO::ByteString" : "lib/PDF/DAO/ByteString.pm",
"PDF::DAO::Coercer" : "lib/PDF/DAO/Coercer.pm",
"PDF::DAO::DateString" : "lib/PDF/DAO/DateString.pm",
"PDF::DAO::Dict" : "lib/PDF/DAO/Dict.pm",
"PDF::DAO::Int" : "lib/PDF/DAO/Int.pm",
"PDF::DAO::Loader" : "lib/PDF/DAO/Loader.pm",
"PDF::DAO::Name" : "lib/PDF/DAO/Name.pm",
"PDF::DAO::Null" : "lib/PDF/DAO/Null.pm",
"PDF::DAO::Real" : "lib/PDF/DAO/Real.pm",
"PDF::DAO::Stream" : "lib/PDF/DAO/Stream.pm",
"PDF::DAO::TextString" : "lib/PDF/DAO/TextString.pm",
"PDF::DAO::Tie" : "lib/PDF/DAO/Tie.pm",
"PDF::DAO::Tie::Array" : "lib/PDF/DAO/Tie/Array.pm",
"PDF::DAO::Tie::Hash" : "lib/PDF/DAO/Tie/Hash.pm",
"PDF::DAO::Type::Encrypt" : "lib/PDF/DAO/Type/Encrypt.pm",
"PDF::DAO::Type::Info" : "lib/PDF/DAO/Type/Info.pm",
"PDF::DAO::Type::ObjStm" : "lib/PDF/DAO/Type/ObjStm.pm",
"PDF::DAO::Type::XRef" : "lib/PDF/DAO/Type/XRef.pm",
"PDF::DAO::Util" : "lib/PDF/DAO/Util.pm",
"PDF::IO" : "lib/PDF/IO.pm",
"PDF::IO::Blob" : "lib/PDF/IO/Blob.pm",
"PDF::IO::Crypt" : "lib/PDF/IO/Crypt.pm",
"PDF::IO::Crypt::AES" : "lib/PDF/IO/Crypt/AES.pm",
"PDF::IO::Crypt::AST" : "lib/PDF/IO/Crypt/AST.pm",
"PDF::IO::Crypt::PDF" : "lib/PDF/IO/Crypt/PDF.pm",
"PDF::IO::Crypt::RC4" : "lib/PDF/IO/Crypt/RC4.pm",
"PDF::IO::Filter" : "lib/PDF/IO/Filter.pm",
"PDF::IO::Filter::ASCII85" : "lib/PDF/IO/Filter/ASCII85.pm",
"PDF::IO::Filter::ASCIIHex" : "lib/PDF/IO/Filter/ASCIIHex.pm",
"PDF::IO::Filter::Flate" : "lib/PDF/IO/Filter/Flate.pm",
"PDF::IO::Filter::Predictors" : "lib/PDF/IO/Filter/Predictors.pm",
"PDF::IO::Filter::RunLength" : "lib/PDF/IO/Filter/RunLength.pm",
"PDF::IO::Handle" : "lib/PDF/IO/Handle.pm",
"PDF::IO::IndObj" : "lib/PDF/IO/IndObj.pm",
"PDF::IO::Serializer" : "lib/PDF/IO/Serializer.pm",
"PDF::IO::Str" : "lib/PDF/IO/Str.pm",
"PDF::IO::Util" : "lib/PDF/IO/Util.pm",
"PDF::Reader" : "lib/PDF/Reader.pm",
"PDF::Writer" : "lib/PDF/Writer.pm"
},
"resources" : [ ],
"source-url" : "git://github.com/p6-pdf/PDF-p6.git",
"tags" : [
"pdf"
],
"test-depends" : [ ],
"version" : "0.2.7"
}
6 changes: 6 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; dist.ini
name = PDF

[ReadmeFromPod]
; if you want to disable generating README.md from main module's pod, then:
disable = true
2 changes: 1 addition & 1 deletion lib/PDF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use PDF::DAO::Dict;

#| this class represents the top level node in a PDF or FDF document,
#| the trailer dictionary
class PDF
class PDF:ver<0.2.7>
is PDF::DAO::Dict {

use PDF::IO::Serializer;
Expand Down
10 changes: 7 additions & 3 deletions lib/PDF/DAO/Tie.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ role PDF::DAO::Tie {
}

#| generate an indirect reference, include the reader, if spanning documents
method link {
method link {
my \obj-num = $.obj-num;
obj-num && obj-num > 0
?? :ind-ref[ obj-num, $.gen-num, $.reader ]
Expand All @@ -31,6 +31,8 @@ role PDF::DAO::Tie {
my $key = self.tied.accessor-name;
my &accessor = sub (\obj) is rw { obj.rw-accessor( self, :$key ); }
$package.^add_method( $key, &accessor );
$package.^add_method( self.tied.alias, &accessor)
if self.tied.alias;
}
}

Expand All @@ -48,6 +50,7 @@ role PDF::DAO::Tie {
has Bool $.is-indirect = False;
has Bool $.is-inherited = False;
has Str $.accessor-name;
has Str $.alias;
has Code $.coerce = sub ($lval is rw, Mu $type) { PDF::DAO.coerce($lval, $type) };
has UInt $.length;

Expand Down Expand Up @@ -79,7 +82,7 @@ role PDF::DAO::Tie {
$att.tied = $.clone;
$att.tied.type = of-type;
$lval.of-att = $att;

for $lval.values {
next if $_ ~~ Pair | of-type;
($att.tied.coerce)($_, of-type);
Expand Down Expand Up @@ -159,7 +162,7 @@ role PDF::DAO::Tie {
multi method type-check($val, $type = $.type) is default {
with $val {
die "{.WHAT.^name}.$*key: {.gist} - not of type: {$type.gist}"
unless $_ ~~ $type | Pair; #| undereferenced - don't know it's type yet
unless $_ ~~ $type | Pair; #| undereferenced - don't know it's type yet
$_;
}
else {
Expand All @@ -182,6 +185,7 @@ role PDF::DAO::Tie {
when 'indirect' { $att.tied.is-indirect = val }
when 'coerce' { $att.tied.coerce = val }
when 'len' { $att.tied.length = val }
when 'alias' { $att.tied.alias = val }
default { warn "ignoring entry attribute: $_" }
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PDF/IO/Serializer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PDF::IO::Serializer {
my subset DictIndObj of Pair where {.key eq 'ind-obj'
&& .value[2] ~~ Pair
&& .value[2].key eq 'dict'}

#| remove and return the root object (trailer dictionary)
method !get-root(@objects) {
my DictIndObj \root-ind-obj = @objects.shift; # first object is trailer dict
Expand Down
2 changes: 1 addition & 1 deletion lib/PDF/Writer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class PDF::Writer {
),
);
}

multi method write-op('comment', $_) { $.write-comment($_); }

#| ID <bytes> - ImageData
Expand Down
5 changes: 3 additions & 2 deletions t/dao-tie-entry.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 37;
plan 38;

use PDF::DAO::Dict;

Expand All @@ -9,7 +9,7 @@ use PDF::DAO::Dict;
class TestDict
is PDF::DAO::Dict {
use PDF::DAO::Tie;
has Int $.IntReq is entry(:required);
has Int $.IntReq is entry(:required, :alias<required-int>);
has Hash $.DictInd is entry(:indirect);
subset FredDict of Hash where {.<Name> ~~ 'Fred'}
has FredDict $.SubsetDict is entry; # todo
Expand All @@ -18,6 +18,7 @@ use PDF::DAO::Dict;
my $dict;
lives-ok { $dict = TestDict.new( :dict{ :IntReq(42) } ) }, 'dict sanity';
is $dict.IntReq, 42, "dict accessor sanity";
is $dict.required-int, 42, "dict alias accessor";
lives-ok { $dict.IntReq = 43 }, 'dict accessor assignment sanity';
quietly {
dies-ok { $dict.IntReq = 'urrgh' }, 'dict accessor assignment typecheck';
Expand Down

0 comments on commit 6e4d898

Please sign in to comment.