Atompub

 view release on metacpan or  search on metacpan

lib/Atompub/MediaType.pm  view on Meta::CPAN

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    feed       => 'application/atom+xml;type=feed',
    service    => 'application/atomsvc+xml',
    categories => 'application/atomcat+xml',
);
 
__PACKAGE__->mk_accessors(qw(type subtype parameters));
 
use overload (
    q{""}    => \&as_string,
    eq       => \&is_a,
    ne       => \&is_not_a,
    fallback => 1,
);
 
sub new {
    my($class, $arg) = @_;
    my $media_type = $ATOM_TYPE{$arg} || $arg or return;
    my($type, $subtype, $param) = split m{[/;]}, $media_type;
    bless {
        type       => $type,
        subtype    => $subtype,

lib/Atompub/MediaType.pm  view on Meta::CPAN

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    if ($test->subtype eq $test->subtype_major) { # ex. application/xml
        return 0 unless $test->subtype_major eq $self->subtype_major;
    }
    else { # ex. application/atom+xml
        return 0 unless $test->subtype eq $self->subtype;
    }
    return 1 if ! $test->parameters || ! $self->parameters;
    return $test->parameters eq $self->parameters;
}
 
sub is_not_a {
    my($self, @args) = @_;
    !$self->is_a(@args);
}
 
1;
__END__
 
=head1 NAME
 
Atompub::MediaType - a media type object for the Atom Publishing Protocol

lib/Atompub/MediaType.pm  view on Meta::CPAN

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
=head2 $type->parameters
 
=head2 $type->subtype_major
 
=head2 $type->extensions
 
=head2 $type->extension
 
=head2 $type->is_a
 
=head2 $type->is_not_a
 
=head2 $type->as_string
 
=head2 $type->without_parameters
 
 
=head1 SEE ALSO
 
L<Atompub>

t/03.media_type.t  view on Meta::CPAN

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
is $png->without_parameters, 'image/png';
is $png->as_string, 'image/png';
 
is $png->extensions, 'png';
is $png->extension, 'png';
 
ok $png->is_a('*/*');
ok $png->is_a('image/*');
ok $png->is_a('image/png');
 
ok $png->is_not_a('text/*');
ok $png->is_not_a('image/jpeg');
 
is "$png", 'image/png';
 
ok $png eq '*/*';
ok $png ne 'text/*';
 
my $atom = media_type('entry');
isa_ok $atom, 'Atompub::MediaType';
 
is $atom->type, 'application';

t/03.media_type.t  view on Meta::CPAN

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
is $atom->extensions, 'atom';
is $atom->extension, 'atom';
 
ok $atom->is_a('*/*');
ok $atom->is_a('application/*');
ok $atom->is_a('application/xml');
ok $atom->is_a('application/atom+xml');
ok $atom->is_a('application/atom+xml;type=entry');
 
ok $atom->is_not_a('text/*');
ok $atom->is_not_a('application/octet-stream');
ok $atom->is_not_a('application/atom+xml;type=feed');
 
is "$atom", 'application/atom+xml;type=entry';
 
ok $atom eq '*/*';
ok $atom ne 'text/*';



( run in 0.404 second using v1.01-cache-2.11-cpan-55f5a4728d2 )