| 1 | package Protocol::DBus::Message; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Protocol::DBus::Message | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | This class encapsulates a single DBus message. You generally should not | ||||||||||||||||||||||||||||
| 15 | instantiate it directly. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use Protocol::DBus::Marshal (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use Protocol::DBus::Message::Header (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use constant _PROTOCOL_VERSION => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub parse { | ||||||||||||||||||||||||||||
| 25 | 11 | ▶ | my ($class, $buf_sr, $filehandles_ar) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 11 | ▶ | if ( my ($hdr, $hdr_len, $is_be) = Protocol::DBus::Message::Header::parse_simple($buf_sr) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 11 | ▶ | if (length($$buf_sr) >= ($hdr_len + $hdr->[4])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 11 | my $body_sig = $hdr->[6]{ Protocol::DBus::Message::Header::FIELD()->{'SIGNATURE'} }; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 11 | ▶ | if ($hdr->[4]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | die "No SIGNATURE header field!" if !defined $body_sig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 11 | my $body_data; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 11 | ▶ | if ($body_sig) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 8 | local $Protocol::DBus::Marshal::FILEHANDLES = $filehandles_ar; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | ▶ | ($body_data) = Protocol::DBus::Marshal->can( $is_be ? 'unmarshal_be' : 'unmarshal_le' )->($buf_sr, $hdr_len, $body_sig); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 11 | my %self = ( _body_sig => $body_sig ); | |||||||||||||||||||||||||||
| 46 | 11 | @self{'_type', '_flags', '_serial', '_hfields', '_body'} = (@{$hdr}[1, 2, 5, 6], $body_data); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Remove the unmarshaled bytes. | ||||||||||||||||||||||||||||
| 49 | 11 | substr( $$buf_sr, 0, $hdr_len + $hdr->[4], q<> ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 11 | return bless \%self, $class; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return undef; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 6 | ▶ | use constant _REQUIRED => ('type', 'serial', 'hfields'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub new { | ||||||||||||||||||||||||||||
| 61 | 5 | ▶ | my ($class, %opts) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 5 | my @missing = grep { !defined $opts{$_} } _REQUIRED(); | |||||||||||||||||||||||||||
| 64 | 5 | ▶ | die "missing: @missing" if @missing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | ▶ | $opts{'type'} = Protocol::DBus::Message::Header::MESSAGE_TYPE()->{ $opts{'type'} } || die "Bad “type”: '$opts{'type'}'"; | ||||||||||||||||||||||||||
|
Condition50%1/2
{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$opts{'type'}} || die("Bad \342\200\234type\342\200\235: '$opts{'type'}'")
MC/DC0%0/1
{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$opts{'type'}} || die("Bad \342\200\234type\342\200\235: '$opts{'type'}'")
{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$opts{'type'}}
Truth table50%1/2
A
A= {ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$opts{'type'}}
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | my $flags = 0; | |||||||||||||||||||||||||||
| 69 | 5 | ▶ | if ($opts{'flags'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | for my $f (@{ $opts{'flags'} }) { | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | $flags |= Protocol::DBus::Message::Header::FLAG()->{$f} || die "Bad “flag”: $f"; | ||||||||||||||||||||||||||
|
Condition0%0/2
{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$f} || die("Bad \342\200\234flag\342\200\235: $f")
MC/DC0%0/1
{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$f} || die("Bad \342\200\234flag\342\200\235: $f")
{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$f}
Truth table0%0/2
A
A= {ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$f}
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | $opts{'flags'} = $flags; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 5 | my %hfields; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 5 | ▶ | if ($opts{'hfields'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 5 | my $field_num; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 5 | my $fi = 0; | |||||||||||||||||||||||||||
| 83 | 5 | ▶ | while ( $fi < @{ $opts{'hfields'} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 23 | my ($name, $value) = @{ $opts{'hfields'} }[ $fi, 1 + $fi ]; | |||||||||||||||||||||||||||
| 85 | 23 | $fi += 2; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 23 | ▶ | $field_num = Protocol::DBus::Message::Header::FIELD()->{$name} || do { | ||||||||||||||||||||||||||
|
Condition33%1/3
{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$name} || do {
die "Bad \342\200\234hfields\342\200\235 name: \342\200\234$name\342\200\235"
}
MC/DC0%0/2
{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$name} || do {
die "Bad \342\200\234hfields\342\200\235 name: \342\200\234$name\342\200\235"
}
{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$name}
do {
die "Bad \342\200\234hfields\342\200\235 name: \342\200\234$name\342\200\235"
}
Truth table33%1/3
A || B
A= {DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$name}B= do {
die "Bad \342\200\234hfields\342\200\235 name: \342\200\234$name\342\200\235"
}
| |||||||||||||||||||||||||||||
| 88 | 0 | die "Bad “hfields” name: “$name”"; | |||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | $hfields{ $field_num } = [ | ||||||||||||||||||||||||||||
| 92 | 23 | Protocol::DBus::Message::Header::FIELD_SIGNATURE()->{$name}, | |||||||||||||||||||||||||||
| 93 | $value, | ||||||||||||||||||||||||||||
| 94 | ]; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 23 | ▶ | if ($field_num == Protocol::DBus::Message::Header::FIELD()->{'SIGNATURE'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 3 | $opts{'body_sig'} = $value; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 5 | $opts{'hfields'} = bless \%hfields, 'Protocol::DBus::Type::Dict'; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 5 | ▶ | if ($opts{'body'}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | die "“body” requires a SIGNATURE header!" if !$opts{'body_sig'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | elsif ($opts{'body_sig'}) { | ||||||||||||||||||||||||||||
| 108 | 0 | die "SIGNATURE header given without “body”!"; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||
| 111 | 2 | $opts{'body'} = \q<>; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 5 | my %self = map { ( "_$_" => $opts{$_} ) } keys %opts; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 5 | return bless \%self, $class; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head1 METHODS | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head2 I<OBJ>->get_header( $NAME ) | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | $NAME is, e.g., C<PATH> or the value of the corresponding | ||||||||||||||||||||||||||||
| 126 | member of C<Protocol::DBus::Message::Header::FIELD()>. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub get_header { | ||||||||||||||||||||||||||||
| 131 | 41 | ▶ | if ($_[1] =~ tr<0-9><>c) { | ||||||||||||||||||||||||||
|
Subroutine
get_header: called CC=3 SCAR=13.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 41 | ▶ | return $_[0]->{'_hfields'}{ Protocol::DBus::Message::Header::FIELD()->{$_[1]} || die("Bad header: “$_[1]”") }; | ||||||||||||||||||||||||||
|
Condition50%1/2
{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$_[1]} || die("Bad header: \342\200\234$_[1]\342\200\235")
MC/DC0%0/1
{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$_[1]} || die("Bad header: \342\200\234$_[1]\342\200\235")
{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$_[1]}
Truth table50%1/2
A
A= {DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{$_[1]}
| |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | return $_[0]->{'_hfields'}{$_[1]}; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 I<OBJ>->get_body() | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Always returned as an array reference or undef. See below about mapping | ||||||||||||||||||||||||||||
| 141 | between D-Bus and Perl. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | sub get_body { | ||||||||||||||||||||||||||||
| 146 | 9 | ▶ | return $_[0]->{'_body'}; | ||||||||||||||||||||||||||
|
Subroutine
get_body: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head2 I<OBJ>->get_type() | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | Returns a number. Cross-reference with the D-Bus specification. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub get_type { | ||||||||||||||||||||||||||||
| 156 | 4 | ▶ | return $_[0]->{'_type'}; | ||||||||||||||||||||||||||
|
Subroutine
get_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head2 I<OBJ>->type_is( $NAME ) | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Convenience method; $NAME is, e.g., C<METHOD_CALL>. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | sub type_is { | ||||||||||||||||||||||||||||
| 166 | 10 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
type_is: called CC=2 SCAR=10.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 10 | ▶ | return $_[0]->{'_type'} == (Protocol::DBus::Message::Header::MESSAGE_TYPE()->{$name} || do { | ||||||||||||||||||||||||||
|
Condition33%1/3
{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$name} || do {
my(@valids) = sort(keys %{{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4};});
die "Invalid type name: $name (valids are: @valids)"
}
MC/DC0%0/2
{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$name} || do {
my(@valids) = sort(keys %{{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4};});
die "Invalid type name: $name (valids are: @valids)"
}
{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$name}
do {
my(@valids) = sort(keys %{{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4};});
die "Invalid type name: $name (valids are: @valids)"
}
Truth table33%1/3
A || B
A= {ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4}->{$name}B= do {
my(@valids) = sort(keys %{{ERROR => 3, METHOD_CALL => 1, METHOD_RETURN => 2, SIGNAL => 4};});
die "Invalid type name: $name (valids are: @valids)"
}
| |||||||||||||||||||||||||||||
| 169 | 0 | my @valids = sort keys %{ Protocol::DBus::Message::Header::MESSAGE_TYPE() }; | |||||||||||||||||||||||||||
| 170 | 0 | die "Invalid type name: $name (valids are: @valids)"; | |||||||||||||||||||||||||||
| 171 | }); | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head2 I<OBJ>->get_flags() | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | Returns a number. Cross-reference with the D-Bus specification. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | sub get_flags { | ||||||||||||||||||||||||||||
| 181 | 4 | ▶ | return $_[0]->{'_flags'}; | ||||||||||||||||||||||||||
|
Subroutine
get_flags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 I<OBJ>->flags_have( @NAME ) | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Convenience method; indicates whether all of the given @NAMES | ||||||||||||||||||||||||||||
| 187 | (e.g., C<NO_AUTO_START>) correspond to flags that are set in the message. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =cut | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | sub flags_have { | ||||||||||||||||||||||||||||
| 192 | 2 | ▶ | my ($self, @names) = @_; | ||||||||||||||||||||||||||
|
Subroutine
flags_have: called CC=5 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 2 | ▶ | die "Need flag names!" if !@names; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 2 | for my $name (@names) { | |||||||||||||||||||||||||||
| 197 | 2 | ▶ | return 0 if !($_[0]->{'_flags'} & (Protocol::DBus::Message::Header::FLAG()->{$name} || do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$name} || do {
my(@valids) = sort(keys %{{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1};});
die "Invalid flag name: \342\200\234$name\342\200\235 (valids are: @valids)"
}
MC/DC0%0/2
{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$name} || do {
my(@valids) = sort(keys %{{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1};});
die "Invalid flag name: \342\200\234$name\342\200\235 (valids are: @valids)"
}
{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$name}
do {
my(@valids) = sort(keys %{{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1};});
die "Invalid flag name: \342\200\234$name\342\200\235 (valids are: @valids)"
}
Truth table33%1/3
A || B
A= {ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1}->{$name}B= do {
my(@valids) = sort(keys %{{ALLOW_INTERACTIVE_AUTHORIZATION => 4, NO_AUTO_START => 2, NO_REPLY_EXPECTED => 1};});
die "Invalid flag name: \342\200\234$name\342\200\235 (valids are: @valids)"
}
| |||||||||||||||||||||||||||||
| 198 | 0 | my @valids = sort keys %{ Protocol::DBus::Message::Header::FLAG() }; | |||||||||||||||||||||||||||
| 199 | 0 | die "Invalid flag name: “$name” (valids are: @valids)"; | |||||||||||||||||||||||||||
| 200 | })); | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 2 | return 1; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head2 I<OBJ>->get_serial() | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Returns a number. | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =cut | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub get_serial { | ||||||||||||||||||||||||||||
| 213 | 5 | ▶ | return $_[0]->{'_serial'}; | ||||||||||||||||||||||||||
|
Subroutine
get_serial: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 6 | our $_use_be; | |||||||||||||||||||||||||||
| 219 | BEGIN { | ||||||||||||||||||||||||||||
| 220 | 6 | ▶ | $_use_be = 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | sub to_string_le { | ||||||||||||||||||||||||||||
| 224 | 5 | ▶ | return _to_string(@_); | ||||||||||||||||||||||||||
|
Subroutine
to_string_le: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | sub to_string_be { | ||||||||||||||||||||||||||||
| 228 | 0 | ▶ | local $_use_be = 1; | ||||||||||||||||||||||||||
|
Subroutine
to_string_be: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 229 | 0 | return _to_string(@_); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 6 | ▶ | use constant _LEADING_BYTE => map { ord } ('l', 'B'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | sub _to_string { | ||||||||||||||||||||||||||||
| 237 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_to_string: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 5 | my ($body_m_sr, $fds_ar); | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 5 | ▶ | if ($self->{'_body_sig'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | ($body_m_sr, $fds_ar) = Protocol::DBus::Marshal->can( $_use_be ? 'marshal_be' : 'marshal_le' )->( | ||||||||||||||||||||||||||||
| 243 | $self->{'_body_sig'}, | ||||||||||||||||||||||||||||
| 244 | 3 | ▶ | $self->{'_body'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | ); | ||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | local $self->{'_hfields'}{ Protocol::DBus::Message::Header::FIELD()->{'UNIX_FDS'} } = [ | ||||||||||||||||||||||||||||
| 249 | 5 | ▶ | Protocol::DBus::Message::Header::FIELD_SIGNATURE()->{'UNIX_FDS'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$fds_ar and @$fds_ar
MC/DC0%0/2
$fds_ar and @$fds_ar
$fds_ar
@$fds_ar
Truth table66%2/3
A and B
A= $fds_arB= @$fds_ar
| |||||||||||||||||||||||||||||
| 250 | 0 + @$fds_ar, | ||||||||||||||||||||||||||||
| 251 | ] if $fds_ar && @$fds_ar; | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | my $data = [ | ||||||||||||||||||||||||||||
| 254 | (_LEADING_BYTE())[ $_use_be ], | ||||||||||||||||||||||||||||
| 255 | $self->{'_type'}, | ||||||||||||||||||||||||||||
| 256 | $self->{'_flags'}, | ||||||||||||||||||||||||||||
| 257 | _PROTOCOL_VERSION(), | ||||||||||||||||||||||||||||
| 258 | $body_m_sr ? length( $$body_m_sr ) : 0, | ||||||||||||||||||||||||||||
| 259 | $self->{'_serial'}, | ||||||||||||||||||||||||||||
| 260 | 5 | ▶ | $self->{'_hfields'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | ]; | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 5 | ▶ | my ($buf_sr) = Protocol::DBus::Marshal->can( $_use_be ? 'marshal_be' : 'marshal_le' )->( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | Protocol::DBus::Message::Header::SIGNATURE(), | ||||||||||||||||||||||||||||
| 265 | $data, | ||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 5 | Protocol::DBus::Pack::align_str($$buf_sr, 8); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 5 | ▶ | $$buf_sr .= $$body_m_sr if $body_m_sr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 5 | return( $buf_sr, $fds_ar ); | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =head1 MAPPING D-BUS TO PERL | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | =over | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =item * Numeric and string types are represented as plain Perl scalars. | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =item * UNIX_FDs are normally represented as Perl filehandle objects. | ||||||||||||||||||||||||||||
| 284 | If Protocol::DBus receives a UNIX_FD that doesn’t correspond to a received | ||||||||||||||||||||||||||||
| 285 | file descriptor, the UNIX_FD will be represented as the number passed in | ||||||||||||||||||||||||||||
| 286 | the raw D-Bus message, and a warning is thrown. | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =item * By default, variant signatures are discarded, and the values are | ||||||||||||||||||||||||||||
| 289 | given by themselves. See L<Protocol::DBus::Peer>’s | ||||||||||||||||||||||||||||
| 290 | C<preserve_variant_signatures()> if you need an alternative mapping | ||||||||||||||||||||||||||||
| 291 | method that preserves the signatures. | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =item * Other containers are represented as blessed references: | ||||||||||||||||||||||||||||
| 294 | C<Protocol::DBus::Type::Dict>, C<Protocol::DBus::Type::Array>, and | ||||||||||||||||||||||||||||
| 295 | C<Protocol::DBus::Type::Struct>. Currently these are just plain hash and | ||||||||||||||||||||||||||||
| 296 | array references that are bless()ed; i.e., the classes themselves have no | ||||||||||||||||||||||||||||
| 297 | methods defined (and aren’t even defined Perl namespaces). | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | =back | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | =head1 MAPPING PERL TO D-BUS | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =over | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =item * Use plain Perl scalars to represent all numeric and string types. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =item * Use plain Perl filehandle objects to represent UNIX_FDs. | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =item * Use array references to represent D-Bus arrays and structs. | ||||||||||||||||||||||||||||
| 310 | Use hash references for dicts. | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =item * Use a two-member array reference—signature then value—to represent | ||||||||||||||||||||||||||||
| 313 | a D-Bus variant. (Note the inconsistency with the reverse mapping.) | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | =back | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =head2 Examples | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | =over | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | =item * C<s(s)> - C<( $s0, [ $s1 ] )> | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | =item * C<a(s)> - C<( \@ss )> | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | =item * C<a{ss}> - C<( \%ss )> | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | =back | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | =cut | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 6 | 1; | |||||||||||||||||||||||||||